Computer Programming Contest Preparation

ToolBox - Source for: 125/12503/a.c



/home/toolbox/public_html/solutions/125/12503/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: 2020-09-01
   20  * Purpose: fun
   21  * Problem: 12503
   22  */
   23 
   24 /*
   25  * This template reads data a specified number of times.
   26  */
   27 
   28 #define MAX_MOVES 102
   29 #define MAX_LINE 132
   30 
   31 int numberOfTimes;
   32 int numMoves;
   33 int moves[MAX_MOVES];
   34 char str[MAX_LINE];
   35 
   36 void init()
   37 {
   38     /* FUNCTION init */
   39     scanf("%d ", &numberOfTimes);
   40 } /* FUNCTION init */
   41 
   42 void dump()
   43 {
   44     /* FUNCTION dump */
   45 } /* FUNCTION dump */
   46 
   47 void getInput()
   48 {
   49     /* FUNCTION getInput */
   50     scanf(" %d ", &numMoves);
   51 } /* FUNCTION getInput */
   52 
   53 void process()
   54 {
   55     /* FUNCTION process */
   56     int i;
   57     int pos = 0;
   58     int tmp;
   59 
   60     for (i=1; i<=numMoves; i++)
   61         {
   62             /* get each move */
   63             scanf(" %[^\n]",str);
   64             switch (str[0])
   65                 {
   66                 /* switch */
   67                 case 'L':
   68                     moves[i] = -1;
   69                     break;
   70                 case 'R':
   71                     moves[i] = 1;
   72                     break;
   73                 default:
   74                     /* start scanf after SAME AS */
   75                     sscanf(&str[7], " %d ", &tmp);
   76                     moves[i] = moves[tmp];
   77                 } /* switch */
   78             pos = pos + moves[i];
   79         } /* get each move */
   80     printf("%d\n", pos);
   81 } /* FUNCTION process */
   82 
   83 int main()
   84 {
   85     /* main */
   86     int i;
   87 
   88     init();
   89     for (i=0; i<numberOfTimes; i++)
   90         {
   91             /* while */
   92             getInput();
   93             process();
   94         } /* while */
   95 
   96     return EXIT_SUCCESS;
   97 } /* main */
   98 
   99