Computer Programming Contest Preparation

ToolBox - Source for: 100/10018/a.c



/home/toolbox/public_html/solutions/100/10018/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:
   17  *    Date:
   18  * Purpose:
   19  * Problem:
   20  */
   21 
   22 /*
   23  * This template reads data until a terminating value is reached.
   24  */
   25 
   26 int num;
   27 int iter;
   28 
   29 void init()
   30 {
   31     /* FUNCTION init */
   32 } /* FUNCTION init */
   33 
   34 void dump()
   35 {
   36     /* FUNCTION dump */
   37 } /* FUNCTION dump */
   38 
   39 void getInput()
   40 {
   41     /* FUNCTION getInput */
   42     scanf("%d ", &num);
   43 } /* FUNCTION getInput */
   44 
   45 int invert(int n)
   46 {
   47     int temp = 0;
   48     while ( 0 < n )
   49         {
   50             temp = temp*10 + n % 10;
   51             n /= 10;
   52         }
   53     return temp;
   54 }
   55 
   56 void process()
   57 {
   58     /* FUNCTION process */
   59     int temp;
   60     iter = 0;
   61 
   62     temp = invert(num);
   63     while (temp != num)
   64         {
   65             DEBUG printf("%u %u\n", num, temp);
   66             iter++;
   67             num += temp;
   68             temp = invert(num);
   69         }
   70     printf("%d %u\n", iter, num);
   71 
   72 } /* FUNCTION process */
   73 
   74 int main ()
   75 {
   76     /* main */
   77     int count;
   78     int i;
   79     init();
   80     scanf("%d ", &count);
   81     for (i=0; i < count; i++)
   82         {
   83             /* while */
   84             getInput();
   85             process();
   86         } /* while */
   87 
   88     return EXIT_SUCCESS;
   89 } /* main */
   90