Computer Programming Contest Preparation

ToolBox - Source for: 2/272/judged.c



/home/toolbox/public_html/solutions/2/272/judged.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 #define MAX_LINE 133
   15 
   16 /* fprintf(stderr, "functionName: message", varslist); */
   17 
   18 /*
   19  *  Author: Isaac Traxler
   20  *    Date: 2014-10
   21  * Purpose: fun
   22  * Problem: 272 - TeX Quotes
   23  */
   24 
   25 /*
   26  * This template reads data a specified number of times.
   27  */
   28 
   29 char line[MAX_LINE];
   30 char outLine[MAX_LINE];
   31 char quotes[2] = {'`', '\''};
   32 int  flip[2] = {1, 0};
   33 int  inside = 0;
   34 
   35 void dump()
   36 {
   37     /* FUNCTION dump */
   38 } /* FUNCTION dump */
   39 
   40 int getInput()
   41 {
   42     /* FUNCTION getInput */
   43     int dataReadFlag;
   44 
   45     fgets(line, MAX_LINE, stdin);
   46     line[strlen(line)-1] = '\0';   /* take care of newline */
   47     DEBUG printf("%d: [%s]\n", strlen(line), line);
   48     dataReadFlag = ! feof(stdin);
   49     return (dataReadFlag);
   50 } /* FUNCTION getInput */
   51 
   52 void process()
   53 {
   54     /* FUNCTION process */
   55     int i;
   56     int j;
   57 
   58     for (i=0, j=0; i<strlen(line); i++)
   59         {
   60             /* for */
   61             if ('"' == line[i])
   62                 {
   63                     /* found a quote */
   64                     outLine[j++] = quotes[inside];
   65                     outLine[j++] = quotes[inside];
   66                     inside = flip[inside];
   67                 } /* found a quote */
   68             else
   69                 {
   70                     /* not a quote -- just transcribe */
   71                     outLine[j++] = line[i];
   72                 } /* not a quote -- just transcribe */
   73         } /* for */
   74     outLine[j] = 0;
   75     printf("%s\n", outLine);
   76 } /* FUNCTION process */
   77 
   78 int main ()
   79 {
   80     /* main */
   81     int moreToDo;
   82 
   83     moreToDo = getInput();
   84     while (moreToDo)
   85         {
   86             /* while */
   87             process();
   88             moreToDo = getInput();
   89         } /* while */
   90 
   91     return EXIT_SUCCESS;
   92 } /* main */
   93 
   94