Computer Programming Contest Preparation

ToolBox - Source for: 3/300/a.c



/home/toolbox/public_html/solutions/3/300/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:2021-01-28
   20  * Purpose: fun
   21  * Problem: 300 Maya Calendar
   22  */
   23 
   24 /*
   25  * This template reads data a specified number of times.
   26  */
   27 
   28 #define pop 335
   29 #define no 221
   30 #define zip 339
   31 #define zotz 471
   32 #define tzec 438
   33 #define xul 345
   34 #define yoxkin 674
   35 #define mol 328
   36 #define chen 414
   37 #define yax 338
   38 #define zac 318
   39 #define ceh 304
   40 #define mac 305
   41 #define kankin 636
   42 #define muan 433
   43 #define pax 329
   44 #define koyab 534
   45 #define cumhu 546
   46 #define uayet 552
   47 
   48 
   49 int numberOfTimes;
   50 int hday;
   51 int hyear;
   52 char hmonth[10];
   53 int tnum;
   54 int tyear;
   55 char tname[20][10] =
   56 {
   57     "imix",
   58     "ik",
   59     "akbal",
   60     "kan",
   61     "chicchan",
   62     "cimi",
   63     "manik",
   64     "lamat",
   65     "muluk",
   66     "ok",
   67     "chuen",
   68     "eb",
   69     "ben",
   70     "ix",
   71     "mem",
   72     "cib",
   73     "caban",
   74     "eznab",
   75     "canac",
   76     "ahau"
   77 };
   78 
   79 void init()
   80 {
   81     /* FUNCTION init */
   82     scanf("%d ", &numberOfTimes);
   83     printf("%d\n", numberOfTimes);
   84 } /* FUNCTION init */
   85 
   86 void dump()
   87 {
   88     /* FUNCTION dump */
   89 } /* FUNCTION dump */
   90 
   91 void getInput()
   92 {
   93     /* FUNCTION getInput */
   94     scanf("%d. %s %d ", &hday, hmonth, &hyear);
   95 } /* FUNCTION getInput */
   96 
   97 /*******************************
   98  * hash for each h month
   99  * 335 pop
  100  * 221 no
  101  * 339 zip
  102  * 471 zotz
  103  * 438 tzec
  104  * 345 xul
  105  * 674 yoxkin
  106  * 328 mol
  107  * 414 chen
  108  * 338 yax
  109  * 318 zac
  110  * 304 ceh
  111  * 305 mac
  112  * 636 kankin
  113  * 433 muan
  114  * 329 pax
  115  * 534 koyab
  116  * 546 cumhu
  117  * 552 uayet
  118  ************************/
  119 
  120 int hashMonth(char word[])
  121 {
  122     /* FUNCTION hashMonth */
  123     int tot = 0;
  124     int sln;
  125     int i;
  126 
  127     sln = strlen(word);
  128     for (i=0; i<sln; i++)
  129         {
  130             /* for */
  131             tot = tot + word[i];
  132         } /* for */
  133     return tot;
  134 } /* FUNCTION hashMonth */
  135 
  136 int countDaysHmonth(char mnt[])
  137 {
  138     /* FUNCTION countDaysHmonth */
  139     int dys;
  140     int tmp;
  141 
  142     tmp = hashMonth(hmonth);
  143     switch (tmp)
  144         {
  145             /* switch */
  146         case pop:
  147             dys = 0;
  148             break;
  149         case no:
  150             dys = 20;
  151             break;
  152         case zip:
  153             dys = 40;
  154             break;
  155         case zotz:
  156             dys = 60;
  157             break;
  158         case tzec:
  159             dys = 80;
  160             break;
  161         case xul:
  162             dys = 100;
  163             break;
  164         case yoxkin:
  165             dys = 120;
  166             break;
  167         case mol:
  168             dys = 140;
  169             break;
  170         case chen:
  171             dys = 160;
  172             break;
  173         case yax:
  174             dys = 180;
  175             break;
  176         case zac:
  177             dys = 200;
  178             break;
  179         case ceh:
  180             dys = 220;
  181             break;
  182         case mac:
  183             dys = 240;
  184             break;
  185         case kankin:
  186             dys = 260;
  187             break;
  188         case muan:
  189             dys = 280;
  190             break;
  191         case pax:
  192             dys = 300;
  193             break;
  194         case koyab:
  195             dys = 320;
  196             break;
  197         case cumhu:
  198             dys = 340;
  199             break;
  200         case uayet:
  201             dys = 360;
  202             break;
  203         } /* switch */
  204     return dys;
  205 } /* FUNCTION countDaysHmonth */
  206 
  207 void process()
  208 {
  209     /* FUNCTION process */
  210     int days;
  211     int tmp;
  212 
  213     DEBUG printf("%d-%s-%d\n", hday, hmonth, hyear);
  214     days = (hyear * 365) + countDaysHmonth(hmonth) + hday;
  215     tyear = days / 260;
  216     tmp = days % 260;
  217     tnum = (tmp % 13 ) + 1;
  218     tmp = tmp % 20;
  219     DEBUG printf("%d ", tmp);
  220     printf("%d %s %d\n", tnum, tname[tmp], tyear);
  221 } /* FUNCTION process */
  222 
  223 int main()
  224 {
  225     /* main */
  226     int i;
  227 
  228     init();
  229     for (i=0; i<numberOfTimes; i++)
  230         {
  231             /* while */
  232             getInput();
  233             process();
  234         } /* while */
  235 
  236     return EXIT_SUCCESS;
  237 } /* main */
  238 
  239