/home/toolbox/public_html/solutions/111/11150/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 #define MAX_LINE 257
16
17 /*
18 * Author: Isaac Traxler
19 * Date: 2016-03-29
20 * Purpose: fun
21 * Problem: 11150 - Cola
22 */
23
24 /*
25 * This template reads lines of data at a time until end of file.
26 */
27
28 int num;
29
30 void init()
31 {
32 /* FUNCTION init */
33 } /* FUNCTION init */
34
35 void dump()
36 {
37 /* FUNCTION dump */
38 } /* FUNCTION dump */
39
40 int getInput()
41 {
42 /* FUNCTION getInput */
43 int dataReadFlag;
44
45 dataReadFlag = (1 == scanf(" %d ", &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 = start;
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 t = drink(num, 2);
90 if (t > mx )
91 {
92 mx = t;
93 }
94 printf("%d\n", mx);
95 } /* FUNCTION process */
96
97 int main()
98 {
99 /* main */
100 int moreToDo;
101
102 init();
103 moreToDo = getInput();
104 while (moreToDo)
105 {
106 /* while */
107 process();
108 moreToDo = getInput();
109 } /* while */
110
111 return EXIT_SUCCESS;
112 } /* main */
113