Computer Programming Contest Preparation

ToolBox - Source for: 106/10684/a.c



/home/toolbox/public_html/solutions/106/10684/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  *  Author: Isaac Traxler
   17  *    Date: 2018-08-27
   18  * Purpose: fun
   19  * Problem: 10684
   20  */
   21 
   22 /*
   23  * This template reads data until a terminating value is reached.
   24  */
   25 
   26 int cnt;
   27 
   28 void init()
   29 {
   30     /* FUNCTION init */
   31 } /* FUNCTION init */
   32 
   33 void dump()
   34 {
   35     /* FUNCTION dump */
   36 } /* FUNCTION dump */
   37 
   38 int getInput()
   39 {
   40     /* FUNCTION getInput */
   41     int dataReadFlag;
   42 
   43     scanf(" %d ", &cnt);
   44     dataReadFlag = (0 < cnt);
   45     return (dataReadFlag);
   46 } /* FUNCTION getInput */
   47 
   48 void process()
   49 {
   50     /* FUNCTION process */
   51     int tot = 0;
   52     int i;
   53     int num;
   54     int mx = -1;
   55 
   56     for (i=0; i<cnt; i++)
   57         {
   58             /* for */
   59             scanf(" %d ", &num);
   60             if ((tot + num) > num)
   61                 {
   62                     /* continue sequence */
   63                     tot = tot + num;
   64                 } /* continue sequence */
   65             else
   66                 {
   67                     /* start a new sequence */
   68                     tot = num;
   69                 } /* start a new sequence */
   70             if ((0 < num) && (tot > mx))
   71                 {
   72                     /* new max found */
   73                     mx = tot;
   74                 } /* new max found */
   75         } /* for */
   76     if (0 > mx)
   77         {
   78             /* never found a winning bet */
   79             printf("Losing streak.\n");
   80         } /* never found a winning bet */
   81     else
   82         {
   83             /* best streak */
   84             printf("The maximum winning streak is %d.\n", mx);
   85         } /* best streak */
   86 } /* FUNCTION process */
   87 
   88 int main()
   89 {
   90     /* main */
   91     int moreToDo;
   92 
   93     init();
   94     moreToDo = getInput();
   95     while (moreToDo)
   96         {
   97             /* while */
   98             process();
   99             moreToDo = getInput();
  100         } /* while */
  101 
  102     return EXIT_SUCCESS;
  103 } /* main */
  104