Computer Programming Contest Preparation

ToolBox - Source for: 118/11877/a.c



/home/toolbox/public_html/solutions/118/11877/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: 2016-09-11
   18  * Purpose: fun
   19  * Problem: 11877 - The Coco-Cola Store
   20  * Similar to 11150
   21  */
   22 
   23 /*
   24  * This template reads data until a terminating value is reached.
   25  */
   26 
   27 int num;
   28 
   29 void init()
   30 {
   31     /* FUNCTION init */
   32 } /* FUNCTION init */
   33 
   34 void dump()
   35 {
   36     /* FUNCTION dump */
   37 } /* FUNCTION dump */
   38 
   39 int getInput()
   40 {
   41     /* FUNCTION getInput */
   42     int dataReadFlag;
   43 
   44     scanf(" %d ", &num);
   45     dataReadFlag = 0 != num;
   46     return (dataReadFlag);
   47 } /* FUNCTION getInput */
   48 
   49 int drink(int start, int borrow)
   50 {
   51     /* FUNCTION drink */
   52     int tot;
   53     int tmp;
   54     int empty;
   55     int toReturn = -1;
   56 
   57     empty = borrow;
   58     tmp = start;
   59     tot = 0;
   60     while (0 < tmp)
   61         {
   62             /* while more to drink */
   63             DEBUG printf("tmp=[%d] tot=[%d] empty=[%d]\n", tmp, tot, empty);
   64             tmp = tmp + empty;
   65             tot = tot + (tmp / 3);
   66             empty = tmp % 3;
   67             tmp = tmp / 3;
   68         } /* while more to drink */
   69     if (borrow <= empty)
   70         {
   71             toReturn = tot;
   72         }
   73     return toReturn;
   74 
   75 } /* FUNCTION drink */
   76 
   77 void process()
   78 {
   79     /* FUNCTION process */
   80     int mx;
   81     int t;
   82 
   83     mx = drink(num, 0);
   84     t = drink(num, 1);
   85     if (t > mx )
   86         {
   87             mx = t;
   88         }
   89     printf("%d\n", mx);
   90 } /* FUNCTION process */
   91 
   92 int main()
   93 {
   94     /* main */
   95     int moreToDo;
   96 
   97     init();
   98     moreToDo = getInput();
   99     while (moreToDo)
  100         {
  101             /* while */
  102             process();
  103             moreToDo = getInput();
  104         } /* while */
  105 
  106     return EXIT_SUCCESS;
  107 } /* main */
  108