Computer Programming Contest Preparation

ToolBox - Source for: 7/713/b.c



/home/toolbox/public_html/solutions/7/713/b.c
    1 #include <stdio.h>
    2 #include <strings.h>
    3 #include <sys/types.h>
    4 #include <sys/stat.h>
    5 #include <fcntl.h>
    6 
    7 #define TRUE  (1 == 1)
    8 #define FALSE (1 != 1)
    9 
   10 #define DEBUG if (TRUE)
   11 #define DEBUG1 if (FALSE)
   12 #define DEBUG2 if (FALSE)
   13 
   14 /* fprintf(stderr, "functionName: message", varslist); */
   15 
   16 /*
   17  *  Author: Isaac Traxler
   18  *    Date: March 1, 2016
   19  * Purpose: fun
   20  * Problem: 713 - Adding Reversed Numbers
   21  */
   22 
   23 /*
   24  * This template reads data a specified number of times.
   25  */
   26 
   27 int numberOfTimes;
   28 unsigned long long int num1, num2;
   29 unsigned long long int rsum;
   30 
   31 int init()
   32 {
   33     /* FUNCTION init */
   34     scanf("%d ", &numberOfTimes);
   35 } /* FUNCTION init */
   36 
   37 void dump()
   38 {
   39     /* FUNCTION dump */
   40 } /* FUNCTION dump */
   41 
   42 void getInput()
   43 {
   44     /* FUNCTION getInput */
   45     scanf(" %llu %llu ", &num1, &num2);
   46     DEBUG1 printf(" Read in: %llu %llu\n", num1, num2);
   47 } /* FUNCTION getInput */
   48 
   49 
   50 
   51 unsigned long long int reverse(unsigned long long int n)
   52 {
   53     /* FUNCTION reverse */
   54     unsigned long long int tot = 0;
   55     int digit;
   56     /* <goodness> */
   57     /* double bigarray[1000]*/
   58     /* </goodness> */
   59 
   60     while (0 < n)
   61         {
   62             /* <badness> */
   63             /* double bigarray[1000]*/
   64             /* </badness> */
   65             digit = n % 10;
   66             tot = tot * 10 + digit;
   67             n = n / 10;
   68         }
   69 
   70     return tot;
   71 } /* FUNCTION reverse */
   72 
   73 void process()
   74 {
   75     /* FUNCTION process */
   76     unsigned long long int r1, r2, sum;
   77 
   78     r1 = reverse(num1);
   79     DEBUG2 printf(" Reversed: %llu %llu\n", num1, r1);
   80     r2 = reverse(num2);
   81     DEBUG2 printf(" Reversed: %llu %llu\n", num2, r2);
   82     sum = r1 + r2;
   83     rsum =  reverse(sum);
   84 
   85     printf("%llu\n", rsum);
   86 } /* FUNCTION process */
   87 
   88 int main ()
   89 {
   90     /* main */
   91     int i;
   92 
   93     init();
   94     for (i=0; i<numberOfTimes; i++)
   95         {
   96             /* while */
   97             getInput();
   98             process();
   99         } /* while */
  100 
  101     return 1;
  102 } /* main */
  103