Computer Programming Contest Preparation

ToolBox - Source for: 112/11219/a.c



/home/toolbox/public_html/solutions/112/11219/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 <stdlib.h>
    7 #include <math.h>
    8 #include <stdint.h>
    9 
   10 #define TRUE  (1 == 1)
   11 #define FALSE (1 != 1)
   12 
   13 #define DEBUG if (FALSE)
   14 
   15 /* fprintf(stderr, "functionName: message", varslist); */
   16 
   17 /*
   18  *  Author: Isaac Traxler
   19  *    Date: 2018/02/19
   20  * Purpose: fun
   21  * Problem: 11219 - How old are you?
   22  */
   23 
   24 /*
   25  * This template reads data a specified number of times.
   26  */
   27 
   28 #define MAX_LENGTH 255
   29 
   30 int numberOfTimes;
   31 char line[MAX_LENGTH];
   32 int current;
   33 int birth;
   34 
   35 void init()
   36 {
   37     /* FUNCTION init */
   38     scanf(" %d ", &numberOfTimes);
   39 } /* FUNCTION init */
   40 
   41 void dump()
   42 {
   43     /* FUNCTION dump */
   44 } /* FUNCTION dump */
   45 
   46 void getInput()
   47 {
   48     /* FUNCTION getInput */
   49     /* get current date */
   50     scanf(" %s ", line);
   51     current = (line[6]-'0')*10000000 + (line[7]-'0')*1000000 + (line[8]-'0')*100000 + (line[9]-'0')*10000 +
   52               (line[3]-'0')*1000 + (line[4]-'0')*100 + (line[0]-'0')*10 + (line[1]-'0');
   53     DEBUG printf("[%s] %d\n", line, current);
   54 
   55     /* get birth date */
   56     scanf(" %s ", line);
   57     birth = (line[6]-'0')*10000000 + (line[7]-'0')*1000000 + (line[8]-'0')*100000 + (line[9]-'0')*10000 +
   58             (line[3]-'0')*1000 + (line[4]-'0')*100 + (line[0]-'0')*10 + (line[1]-'0');
   59     DEBUG printf("[%s] %d\n", line, birth);
   60 } /* FUNCTION getInput */
   61 
   62 void process()
   63 {
   64     /* FUNCTION process */
   65     int dif;
   66 
   67     dif = current - birth;
   68     if (0 > dif)
   69         {
   70             printf("Invalid birth date\n");
   71         }
   72     else if (current == birth)
   73         {
   74             printf("0\n");
   75         }
   76     else
   77         {
   78             /* calculate years */
   79             dif = dif / 10000;
   80             if (130 < dif)
   81                 {
   82                     printf("Check birth date\n");
   83                 }
   84             else
   85                 {
   86                     printf("%d\n", dif);
   87                 }
   88         } /* calculate years */
   89 } /* FUNCTION process */
   90 
   91 int main()
   92 {
   93     /* main */
   94     int i;
   95 
   96     init();
   97     for (i=0; i<numberOfTimes; i++)
   98         {
   99             /* while */
  100             getInput();
  101             printf("Case #%d: ", i+1);
  102             process();
  103         } /* while */
  104 
  105     return EXIT_SUCCESS;
  106 } /* main */
  107 
  108