Computer Programming Contest Preparation

ToolBox - Source for: 17/1727/b.c



/home/toolbox/public_html/solutions/17/1727/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 <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-11-14
   20  * Purpose: fun
   21  * Problem: 1727
   22  */
   23 
   24 /*
   25  * This template reads data a specified number of times.
   26  */
   27 
   28 #define SUN ('S' * 100 + 'U')
   29 #define MON ('M' * 100 + 'O')
   30 #define TUE ('T' * 100 + 'U')
   31 #define WED ('W' * 100 + 'E')
   32 #define THU ('T' * 100 + 'H')
   33 #define FRI ('F' * 100 + 'R')
   34 #define SAT ('S' * 100 + 'A')
   35 
   36 int numberOfTimes;
   37 char mnth[10];
   38 char day[10];
   39 
   40 void init()
   41 {
   42     /* FUNCTION init */
   43     scanf("%d ", &numberOfTimes);
   44 } /* FUNCTION init */
   45 
   46 void dump()
   47 {
   48     /* FUNCTION dump */
   49 } /* FUNCTION dump */
   50 
   51 int daysInMonth()
   52 {
   53     /* FUNCTION daysInMonth */
   54     int ret = 31;
   55     switch (mnth[0])
   56         {
   57         /* switch */
   58         /* January, June, July */
   59         case 'J':
   60             if (('U' == mnth[1]) && ('N' == mnth[2]))
   61                 {
   62                     ret = 30;    /* June */
   63                 }
   64             break;
   65         /* February */
   66         case 'F':
   67             ret = 28;
   68             break;
   69         /* March, May */
   70         case 'M':
   71             break;
   72         /* April, August */
   73         case 'A':
   74             if ('P' == mnth[1])
   75                 {
   76                     ret = 30;    /* april */
   77                 }
   78         /* September */
   79         case 'S':
   80             ret = 30;
   81             break;
   82         /* October */
   83         case 'O':
   84             break;
   85         /* Novemeber */
   86         case 'N':
   87             ret = 30;
   88             break;
   89         /* Decemeber */
   90         case 'D':
   91             break;
   92         } /* switch */
   93     return ret;
   94 } /* FUNCTION daysInMonth */
   95 
   96 void getInput()
   97 {
   98     /* FUNCTION getInput */
   99     scanf(" %s %s ", mnth, day);
  100 } /* FUNCTION getInput */
  101 
  102 int computeDay()
  103 {
  104     /* FUNCTION computeDay */
  105     int ret = -1;
  106 
  107     switch ((day[0] * 100) + day[1])
  108         {
  109         /* switch */
  110         case SUN:
  111             ret = 0;
  112             break;
  113         case MON:
  114             ret = 1;
  115             break;
  116         case TUE:
  117             ret = 2;
  118             break;
  119         case WED:
  120             ret = 3;
  121             break;
  122         case THU:
  123             ret = 4;
  124             break;
  125         case FRI:
  126             ret = 5;
  127             break;
  128         case SAT:
  129             ret = 6;
  130             break;
  131         } /* switch */
  132     return ret;
  133 } /* FUNCTION computeDay */
  134 
  135 void process()
  136 {
  137     /* FUNCTION process */
  138 
  139     printf("sun = %d\n", SUN);
  140     printf("mon = %d\n", MON);
  141     printf("tue = %d\n", TUE);
  142     printf("wed = %d\n", WED);
  143     printf("thu = %d\n", THU);
  144     printf("fri = %d\n", FRI);
  145     printf("sat = %d\n", SAT);
  146     printf("offset = %d\n", computeDay());
  147     printf("days in month = %d  day(%s) %d %d\n", daysInMonth(), day, day[0], day[1]);
  148 
  149     switch (daysInMonth() + computeDay())
  150         {
  151         /* switch */
  152         case 34:
  153             printf("9\n");
  154             break;
  155         case 35:
  156             printf("10\n");
  157             break;
  158         default:
  159             printf("8\n");
  160         } /* switch */
  161 
  162 
  163 
  164 } /* FUNCTION process */
  165 
  166 int main()
  167 {
  168     /* main */
  169     int i;
  170 
  171     init();
  172     for (i=0; i<numberOfTimes; i++)
  173         {
  174             /* while */
  175             getInput();
  176             process();
  177         } /* while */
  178 
  179     return EXIT_SUCCESS;
  180 } /* main */
  181 
  182