/home/toolbox/public_html/solutions/106/10696/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_CACHE 1000000
16
17 /*
18 * Author: Isaac Traxler
19 * Date: 2014-10-29
20 * Purpose: fun
21 * Problem: 10696 - F91
22
23 If N ≤ 100, then f91(N) = f91(f91(N+11));
24 If N ≥ 101, then f91(N) = N-10.
25
26 */
27
28 /*
29 * This template reads data until a terminating value is reached.
30 */
31
32 int num;
33 int cache[MAX_CACHE];
34
35 void init()
36 {
37 /* FUNCTION init */
38 int i;
39
40 for (i=0; i<MAX_CACHE; i++) cache[i] = -1;
41 } /* FUNCTION init */
42
43 void dump()
44 {
45 /* FUNCTION dump */
46 } /* FUNCTION dump */
47
48 int getInput()
49 {
50 /* FUNCTION getInput */
51 int dataReadFlag;
52
53 scanf(" %d ", &num);
54 dataReadFlag = 0 != num;
55 return (dataReadFlag);
56 } /* FUNCTION getInput */
57
58 int f91(int n)
59 {
60 /* FUNCTION f91 */
61 int ret;
62
63 if ((n < MAX_CACHE) && (-1 != cache[n]))
64 {
65 ret = cache[n];
66 }
67 else
68 {
69 /* looks like we need to compute it */
70 if (101 > n)
71 {
72 ret = f91(f91(n+11));
73 }
74 else
75 {
76 ret = n - 10;
77 }
78 } /* looks like we need to compute it */
79 if (n < MAX_CACHE)
80 {
81 cache[n] = ret;
82 }
83 return ret;
84 } /* FUNCTION f91 */
85
86 void process()
87 {
88 /* FUNCTION process */
89 int ans;
90
91 ans = f91(num);
92 printf("f91(%d) = %d\n", num, ans);
93 } /* FUNCTION process */
94
95 int main ()
96 {
97 /* main */
98 int moreToDo;
99
100 init();
101 moreToDo = getInput();
102 while (moreToDo)
103 {
104 /* while */
105 process();
106 moreToDo = getInput();
107 } /* while */
108
109 return EXIT_SUCCESS;
110 } /* main */
111