Computer Programming Contest Preparation

ToolBox - Source for: 2/271/a.c



/home/toolbox/public_html/solutions/2/271/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: 2021-01-28
   19  * Purpose: fun
   20  * Problem: 271 - Simply Syntax
   21  */
   22 
   23 /*
   24  * This template reads lines of data at a time until end of file.
   25  */
   26 
   27 #define MAX_LINE 260
   28 #define N 'N'
   29 #define C 'C'
   30 #define D 'D'
   31 #define E 'E'
   32 #define I 'I'
   33 
   34 #define maxx(a,b) ( { a>b ? a :b; } )
   35 
   36 
   37 char line[MAX_LINE];
   38 int sln;
   39 int mx;
   40 
   41 void init()
   42 {
   43     /* FUNCTION init */
   44 } /* FUNCTION init */
   45 
   46 void dump()
   47 {
   48     /* FUNCTION dump */
   49 } /* FUNCTION dump */
   50 
   51 int getInput()
   52 {
   53     /* FUNCTION getInput */
   54     int dataReadFlag;
   55 
   56     fgets(line, MAX_LINE, stdin);
   57     if (feof(stdin))
   58         dataReadFlag = FALSE;
   59     else
   60         {
   61             /* something to read */
   62             dataReadFlag = TRUE;
   63             line[strlen(line)-1] = 0;
   64         } /* something to read */
   65     return (dataReadFlag);
   66 } /* FUNCTION getInput */
   67 
   68 int testSentence(int i)
   69 {
   70     /* FUNCTION testSentence */
   71     int valid = TRUE;
   72 
   73     valid = (0 < sln);
   74     mx = maxx(mx, i);
   75     if (valid)
   76         {
   77             /* something to process */
   78             switch (line[i])
   79                 {
   80                 /* switch */
   81                 case 'p' ... 'z':
   82                     break;
   83                 case N:
   84                     valid = testSentence(i+1);
   85                     break;
   86                 case C:
   87                 case D:
   88                 case E:
   89                 case I:
   90                     valid = testSentence(i+1);
   91                     if (valid)
   92                         {
   93                             /* get second sentence */
   94                             valid = testSentence(mx + 1);
   95                         } /* get second sentence */
   96                     break;
   97                 } /* switch */
   98         } /* something to process */
   99     return valid;
  100 } /* FUNCTION testSentence */
  101 
  102 void process()
  103 {
  104     /* FUNCTION process */
  105     int valid;
  106 
  107     mx = -1;
  108     sln = strlen(line);
  109     if (0 < sln)
  110         {
  111             /* something to process */
  112             valid = testSentence(0);
  113         } /* something to process */
  114     else
  115         valid = FALSE;
  116     valid = valid && (sln == (mx+1));
  117     if (valid)
  118         printf("YES\n");
  119     else
  120         printf("NO\n");
  121 } /* FUNCTION process */
  122 
  123 int main()
  124 {
  125     /* main */
  126     int moreToDo;
  127 
  128     init();
  129     moreToDo = getInput();
  130     while (moreToDo)
  131         {
  132             /* while */
  133             process();
  134             moreToDo = getInput();
  135         } /* while */
  136 
  137     return EXIT_SUCCESS;
  138 } /* main */
  139