Computer Programming Contest Preparation

ToolBox - Source for: 113/11332/a.c



/home/toolbox/public_html/solutions/113/11332/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: 2015-03-11
   18  * Purpose:
   19  * Problem: 11332
   20  */
   21 
   22 /*
   23  * This template reads data until a terminating value is reached.
   24  */
   25 
   26 #define BIG unsigned long long int
   27 BIG num;
   28 
   29 void init()
   30 {
   31     /* FUNCTION init */
   32 } /* FUNCTION init */
   33 
   34 void dump()
   35 {
   36     /* FUNCTION dump */
   37 } /* FUNCTION dump */
   38 
   39 int getInput()
   40 {
   41     /* FUNCTION getInput */
   42     int dataReadFlag;
   43 
   44     scanf(" %ld ", &num);
   45     printf("%ld\n", num);
   46     dataReadFlag = (0 != num);
   47     return (dataReadFlag);
   48 } /* FUNCTION getInput */
   49 
   50 BIG add(BIG num)
   51 {
   52     /* FUNCTION add */
   53     BIG tot;
   54     BIG tmp;
   55 
   56     tot = 0;
   57     tmp = num;
   58     while (0 < tmp)
   59         {
   60             /* while */
   61             tot = tot + (tmp % 10);
   62             tmp = tmp / 10;
   63         } /* while */
   64     return tot;
   65 } /* FUNCTION add */
   66 
   67 void process()
   68 {
   69     /* FUNCTION process */
   70     while (10 < num)
   71         {
   72             /* while */
   73             num = add(num);
   74         } /* while */
   75     printf("%ld\n", num);
   76 } /* FUNCTION process */
   77 
   78 int main()
   79 {
   80     /* main */
   81     int moreToDo;
   82 
   83     init();
   84     moreToDo = getInput();
   85     while (moreToDo)
   86         {
   87             /* while */
   88             process();
   89             moreToDo = getInput();
   90         } /* while */
   91 
   92     return EXIT_SUCCESS;
   93 } /* main */
   94