Computer Programming Contest Preparation

ToolBox - Source for: 126/12640/b.c



/home/toolbox/public_html/solutions/126/12640/b.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 DEBUG1 if (FALSE)
   14 #define DEBUG if (TRUE)
   15 
   16 
   17 /*
   18  *  Author: Isaac Traxler
   19  *    Date: 2015-10-06
   20  * Purpose: fun
   21  * Problem: 12640 - Largest Sum Game (worst part is input)
   22  */
   23 
   24 /*
   25  * Hard part here is processing it as a line at a time
   26  */
   27 
   28 /*
   29  * This template reads lines of data at a time until end of file.
   30  */
   31 
   32 #define DASH '-'
   33 #define SPACE ' '
   34 
   35 int endOfLine;
   36 int endOfFile = FALSE;
   37 
   38 int getNum()
   39 {
   40     /* FUNCTION getNum */
   41     int num = 0;
   42     int neg = FALSE;
   43     int chr;
   44 
   45     chr = getchar();
   46     if (feof(stdin))
   47         {
   48             endOfFile = TRUE;
   49             endOfLine = TRUE;
   50             return -1;
   51         }
   52     DEBUG printf("skipping: [");
   53     while ((! isdigit(chr)) && (DASH != chr))
   54         {
   55             /* skip any leading whitespace */
   56             DEBUG1 printf("%c", chr);
   57             chr = getchar();
   58         } /* skip any leading whitespace */
   59     /* handle negative sign */
   60     if (DASH == chr)
   61         {
   62             /* found a negative sign */
   63             neg = TRUE;
   64             chr = getchar();
   65             DEBUG printf(" [negative number] ");
   66         } /* found a negative sign */
   67     /* get each digit */
   68     while (isdigit(chr))
   69         {
   70             /* found another digit */
   71             num = (num * 10) + (chr - '0');
   72             chr = getchar();
   73         } /* found another digit */
   74     printf("char after last digit: %d\n", chr);
   75     if (SPACE == chr)
   76         {
   77             /* more numbers on line */
   78             endOfLine = FALSE;
   79             endOfFile = FALSE;
   80         } /* more numbers on line */
   81     else
   82         {
   83             /* end of something */
   84             endOfLine = TRUE;
   85             endOfFile == feof(stdin);
   86         } /* end of something */
   87     if (neg)
   88         {
   89             num = 0 - num;
   90         }
   91     DEBUG printf("num = %d\n", num);
   92     return num;
   93 } /* FUNCTION getNum */
   94 
   95 void process()
   96 {
   97     /* FUNCTION process */
   98     int mx = -999999;
   99     int cur = 0;
  100     int tmp;
  101 
  102     printf("Start line\n");
  103     tmp = getNum();
  104     while (! endOfLine)
  105         {
  106             /* something to process */
  107             tmp = getNum();
  108         } /* something to process */
  109 } /* FUNCTION process */
  110 
  111 int main()
  112 {
  113     /* main */
  114 
  115     while (! endOfFile)
  116         {
  117             /* while */
  118             process();
  119         } /* while */
  120 
  121     return EXIT_SUCCESS;
  122 } /* main */
  123