Computer Programming Contest Preparation

ToolBox - Source for: 119/11933/a.c



/home/toolbox/public_html/solutions/119/11933/a.c
    1 #include <stdio.h>
    2 #include <string.h>
    3 #include <sys/types.h>
    4 #include <sys/stat.h>
    5 #include <fcntl.h>
    6 #include <stdint.h>
    7 #include <math.h>
    8 #include <stdlib.h>
    9 
   10 #define TRUE  (1 == 1)
   11 #define FALSE (1 != 1)
   12 
   13 #define DEBUG if (FALSE)
   14 
   15 /*
   16  *  Author: Isaac Traxler
   17  *    Date: 2017-01-25
   18  * Purpose: fun
   19  * Problem: 11933 - Splitting Number
   20  */
   21 
   22 /*
   23  * This template reads data until a terminating value is reached.
   24  */
   25 
   26 /* 3322222222221111111111
   27  * 1098765432109876543210987654321
   28  * 1010101010101010101010101010101
   29  *   5   5   5   5   5   5   5   5
   30  * 0101010101010101010101010101010
   31  *   A   A   A   A   A   A   A
   32  */
   33 #define A 0x55555555
   34 #define B 0xAAAAAAAA
   35 unsigned int num;
   36 
   37 void init()
   38 {
   39     /* FUNCTION init */
   40 } /* FUNCTION init */
   41 
   42 void dump()
   43 {
   44     /* FUNCTION dump */
   45 } /* FUNCTION dump */
   46 
   47 int getInput()
   48 {
   49     /* FUNCTION getInput */
   50     int dataReadFlag;
   51 
   52     scanf(" %d ", &num);
   53     dataReadFlag = (0 != num);
   54     return (dataReadFlag);
   55 } /* FUNCTION getInput */
   56 
   57 void process()
   58 {
   59     /* FUNCTION process */
   60     unsigned int mask = 1;
   61     unsigned int ab[2] = { 0, 0};
   62     int flip[2] = { 1, 0};
   63     int ptr = 0;
   64 
   65     while (0 < num)
   66         {
   67             /* while */
   68             if (0 != (mask & num))
   69                 {
   70                     /* found a bit on */
   71                     DEBUG printf("num %x %u\n", num, num);
   72                     DEBUG printf("mask %x %u\n", mask, mask);
   73                     DEBUG printf("ab %x %u  %x %u\n", ab[0], ab[0], ab[1], ab[1]);
   74                     ab[ptr] = ab[ptr] + mask;
   75                     ptr = flip[ptr];
   76                     num = num - mask;
   77                 } /* found a bit on */
   78             mask = mask * 2;
   79         } /* while */
   80 
   81     printf("%u %u\n", ab[0], ab[1]);
   82 } /* FUNCTION process */
   83 
   84 int main()
   85 {
   86     /* main */
   87     int moreToDo;
   88 
   89     init();
   90     moreToDo = getInput();
   91     while (moreToDo)
   92         {
   93             /* while */
   94             process();
   95             moreToDo = getInput();
   96         } /* while */
   97 
   98     return EXIT_SUCCESS;
   99 } /* main */
  100