Computer Programming Contest Preparation

ToolBox - Source for: 104/10409/a.c



/home/toolbox/public_html/solutions/104/10409/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: 2020-09-04
   18  * Purpose: fun
   19  * Problem: 10409
   20  */
   21 
   22 /*
   23  * This template reads data until a terminating value is reached.
   24  */
   25 
   26 #define MAX_LINE 132
   27 #define TOP    0
   28 #define NORTH  1
   29 #define WEST   2
   30 #define SOUTH  3
   31 #define EAST   4
   32 #define BOTTOM 5
   33 
   34 int die[6];
   35 int cnt;
   36 char str[MAX_LINE];
   37 
   38 void init()
   39 {
   40     /* FUNCTION init */
   41     die[TOP] = 1;
   42     die[NORTH] = 2;
   43     die[WEST] = 3;
   44     die[SOUTH] = 5;
   45     die[EAST] = 4;
   46     die[BOTTOM] = 6;
   47 } /* FUNCTION init */
   48 
   49 void rollNorth()
   50 {
   51     /* FUNCTION rollNorth */
   52     int tmp;
   53 
   54     tmp = die[TOP];
   55     die[TOP] = die[SOUTH];
   56     die[SOUTH] = die[BOTTOM];
   57     die[BOTTOM] = die[NORTH];
   58     die[NORTH] = tmp;
   59 } /* FUNCTION rollNorth */
   60 
   61 void rollWest()
   62 {
   63     /* FUNCTION rollWest */
   64     int tmp;
   65 
   66     tmp = die[TOP];
   67     die[TOP] = die[EAST];
   68     die[EAST] = die[BOTTOM];
   69     die[BOTTOM] = die[WEST];
   70     die[WEST] = tmp;
   71 } /* FUNCTION rollWest */
   72 
   73 void rollSouth()
   74 {
   75     /* FUNCTION rollSouth */
   76     int tmp;
   77 
   78     tmp = die[TOP];
   79     die[TOP] = die[NORTH];
   80     die[NORTH] = die[BOTTOM];
   81     die[BOTTOM] = die[SOUTH];
   82     die[SOUTH] = tmp;
   83 } /* FUNCTION rollSouth */
   84 
   85 void rollEast()
   86 {
   87     /* FUNCTION rollEast */
   88     int tmp;
   89 
   90     tmp = die[TOP];
   91     die[TOP] = die[WEST];
   92     die[WEST] = die[BOTTOM];
   93     die[BOTTOM] = die[EAST];
   94     die[EAST] = tmp;
   95 } /* FUNCTION rollEast */
   96 
   97 void dump()
   98 {
   99     /* FUNCTION dump */
  100 } /* FUNCTION dump */
  101 
  102 int getInput()
  103 {
  104     /* FUNCTION getInput */
  105     int dataReadFlag;
  106 
  107     scanf(" %d ", &cnt);
  108     dataReadFlag = 0 < cnt;
  109     return (dataReadFlag);
  110 } /* FUNCTION getInput */
  111 
  112 void process()
  113 {
  114     /* FUNCTION process */
  115     int i;
  116 
  117     init();  /* reset die to starting position */
  118     for (i=0; cnt>i; i++)
  119         {
  120             /* for each roll */
  121             scanf(" %s ", str);
  122             DEBUG printf("%d %s\n", die[TOP], str);
  123             switch (str[0])
  124                 {
  125                     /* switch */
  126                 case 'n':
  127                     rollNorth();
  128                     break;
  129                 case 's':
  130                     rollSouth();
  131                     break;
  132                 case 'e':
  133                     rollEast();
  134                     break;
  135                 case 'w':
  136                     rollWest();
  137                     break;
  138                 } /* switch */
  139         } /* for each roll */
  140     printf("%d\n", die[TOP]);
  141 } /* FUNCTION process */
  142 
  143 int main()
  144 {
  145     /* main */
  146     int moreToDo;
  147 
  148     moreToDo = getInput();
  149     while (moreToDo)
  150         {
  151             /* while */
  152             process();
  153             moreToDo = getInput();
  154         } /* while */
  155 
  156     return EXIT_SUCCESS;
  157 } /* main */
  158