Computer Programming Contest Preparation

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



/home/toolbox/public_html/solutions/17/1727/c.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 FRI:
  111             ret = 0;
  112             break;
  113         case SAT:
  114             ret = 1;
  115             break;
  116         case SUN:
  117             ret = 2;
  118             break;
  119         case MON:
  120             ret = 3;
  121             break;
  122         case TUE:
  123             ret = 4;
  124             break;
  125         case WED:
  126             ret = 5;
  127             break;
  128         case THU:
  129             ret = 6;
  130             break;
  131         } /* switch */
  132     return ret;
  133 } /* FUNCTION computeDay */
  134 
  135 void process()
  136 {
  137     /* FUNCTION process */
  138     int mx;
  139     int cnt;
  140 
  141     mx = daysInMonth();
  142     if (28 == mx)
  143         {
  144             printf("8\n";
  145         }  /* feb is always 8 weekend days */
  146     else
  147         {
  148             /* 30 or 31 days */
  149             dy = computeDay();
  150             if ( 6 == dy)
  151                 {
  152                     cnt = 1;
  153                 }
  154             else
  155                 {
  156                     cnt = 2;
  157                 }
  158             mx = mx - (7 - dy);
  159             while (6 < mx)
  160                 {
  161                     /* eat up weeks */
  162                     mx = mx - 7;
  163                     cnt = cnt + 2;
  164                 } /* eat up weeks */
  165             printf("%d\n", cnt);
  166         } /* 30 or 31 days */
  167 
  168 } /* FUNCTION process */
  169 
  170 int main()
  171 {
  172     /* main */
  173     int i;
  174 
  175     init();
  176     for (i=0; i<numberOfTimes; i++)
  177         {
  178             /* while */
  179             getInput();
  180             process();
  181         } /* while */
  182 
  183     return EXIT_SUCCESS;
  184 } /* main */
  185 
  186