/home/toolbox/public_html/solutions/1/100/simple.c
1 //
2 // trivial solution
3 //
4
5 #include <stdio.h>
6
7 #define TRUE (1 == 1)
8 #define FALSE (1 != 1)
9 #define MININT (-999999)
10
11
12 int getInput(int *start, int *stop)
13 {
14 // BEGIN FUNCTION getInput
15 int moreToDo;
16
17 moreToDo = EOF != scanf("%d ", start);
18 // printf("moreToDo=[%d]\n",moreToDo);
19 if (moreToDo)
20 {
21 // if
22 scanf("%d ", stop);
23 } // if
24 return moreToDo;
25 } // END FUNCTION getInput
26
27 int calcOne(int in)
28 {
29 // BEGIN FUNCTION calcOne
30 int retval = 1;
31 if (1 != in)
32 {
33 // then
34 retval = (0 == (in % 2)) ? in / 2 : 3 * in + 1 ;
35 } // then
36 return retval;
37 } // END FUNCTION calcOne
38
39 int calc(int in)
40 {
41 // BEGIN FUNCTION calc
42 int retval;
43 int cnt = 1;
44
45 retval = in;
46 while (1 != retval)
47 {
48 // while
49 cnt++;
50 retval = calcOne(retval);
51 } // while
52 return cnt;
53 } // BEGIN FUNCTION calc
54
55 int process(int start, int stop)
56 {
57 // BEGIN FUNCTION process
58 int i;
59 int max = MININT;
60 int tmp;
61
62 for (i=start; i <= stop; i++)
63 {
64 // for
65 tmp = calc(i);
66 max = (max < tmp) ? tmp : max;
67 } // for
68
69 return max;
70 } // END FUNCTION process
71
72 int main ()
73 {
74 // main
75 int moreToDo; // tell me when to stop
76 int start; // starting point
77 int stop; // stopping point
78 int ans; // calculated answer
79
80 // init();
81 moreToDo = getInput(&start, &stop);
82 while (moreToDo)
83 {
84 // while
85 ans = process(start, stop);
86 printf("%d %d %d\n", start, stop, ans);
87 moreToDo = getInput(&start, &stop);
88 } // while
89
90 return 1;
91 } // main
92