Computer Programming Contest Preparation

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



/home/toolbox/public_html/solutions/100/10035/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: 2014-10-28
   18  * Purpose: fun
   19  * Problem: 10035 - Primary Aritmetic
   20  */
   21 
   22 /*
   23  * This template reads data until a terminating value is reached.
   24  */
   25 
   26 int a;
   27 int b;
   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(" %d %d ", &a, &b);
   45 
   46     dataReadFlag = (a != 0) || (b != 0);
   47     return (dataReadFlag);
   48 } /* FUNCTION getInput */
   49 
   50 void process()
   51 {
   52     /* FUNCTION process */
   53     int cnt = 0;
   54     int carry = 0;
   55 
   56     DEBUG printf("%d %d\n", a, b);
   57     while ((0<carry) || ((a>0) && (b>0)))
   58         {
   59             /* process numbers */
   60             if (9 < ((a % 10) + (b % 10) + carry))
   61                 {
   62                     /* we have a carry */
   63                     cnt++;
   64                     carry = 1;
   65                 } /* we have a carry */
   66             else
   67                 carry = 0;
   68             a = a / 10;
   69             b = b / 10;
   70         } /* process numbers */
   71 
   72     if (0 == cnt)
   73         {
   74             printf("No ");
   75         }
   76     else
   77         {
   78             printf("%d ", cnt);
   79         }
   80 
   81     printf("carry operation");
   82 
   83     if (1 < cnt)
   84         {
   85             printf("s");
   86         }
   87 
   88     printf(".\n");
   89 } /* FUNCTION process */
   90 
   91 int main ()
   92 {
   93     /* main */
   94     int moreToDo;
   95 
   96     init();
   97     moreToDo = getInput();
   98     while (moreToDo)
   99         {
  100             /* while */
  101             process();
  102             moreToDo = getInput();
  103         } /* while */
  104 
  105     return EXIT_SUCCESS;
  106 } /* main */
  107