Computer Programming Contest Preparation

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



/home/toolbox/public_html/solutions/100/10018/b.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 unsigned long num;
   27 unsigned long 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 unsigned long invert(unsigned long n)
   46 {
   47     unsigned long 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     unsigned long temp;
   60     iter = 0;
   61 
   62     temp = invert(num);
   63     while (temp != num)
   64         {
   65             iter++;
   66             num += temp;
   67             temp = invert(num);
   68         }
   69     printf("%u %u\n", iter, num);
   70 
   71 } /* FUNCTION process */
   72 
   73 int main ()
   74 {
   75     /* main */
   76     unsigned long count;
   77     unsigned long i;
   78     init();
   79     scanf("%d ", &count);
   80     for (i=0; i < count; i++)
   81         {
   82             /* while */
   83             getInput();
   84             process();
   85         } /* while */
   86 
   87     return EXIT_SUCCESS;
   88 } /* main */
   89