Computer Programming Contest Preparation

ToolBox - Source for: 15/1585/a.c



/home/toolbox/public_html/solutions/15/1585/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 /*
   17  *  Author: Isaac Traxler
   18  *    Date: 2017-01-22
   19  * Purpose: fun
   20  * Problem: 1585 - Score
   21  */
   22 
   23 /*
   24  * This template reads lines of data at a time until end of file.
   25  */
   26 
   27 #define MAX_LINE 257
   28 #define RIGHT 'O'
   29 #define WRONG 'X'
   30 
   31 char line[MAX_LINE];
   32 int numCases;
   33 
   34 void init()
   35 {
   36     /* FUNCTION init */
   37     scanf(" %d ", &numCases);
   38 } /* FUNCTION init */
   39 
   40 void dump()
   41 {
   42     /* FUNCTION dump */
   43 } /* FUNCTION dump */
   44 
   45 void getInput()
   46 {
   47     /* FUNCTION getInput */
   48     fgets(line, MAX_LINE, stdin);
   49     line[strlen(line)-1] = 0;
   50 } /* FUNCTION getInput */
   51 
   52 void process()
   53 {
   54     /* FUNCTION process */
   55     int i;
   56     int val=0;
   57     int tot = 0;
   58 
   59     for (i=0; i<strlen(line); i++)
   60         {
   61             /* for */
   62             switch (line[i])
   63                 {
   64                 /* switch */
   65                 case RIGHT:
   66                     val++;
   67                     tot = tot + val;
   68                     break;
   69                 case WRONG:
   70                     val = 0;
   71                     break;
   72                 } /* switch */
   73         } /* for */
   74     printf("%d\n", tot);
   75 } /* FUNCTION process */
   76 
   77 int main()
   78 {
   79     /* main */
   80     int i;
   81 
   82     init();
   83     for (i=0; i<numCases; i++)
   84         {
   85             /* for */
   86             getInput();
   87             process();
   88         } /* for */
   89 
   90     return EXIT_SUCCESS;
   91 } /* main */
   92