/home/toolbox/public_html/solutions/6/619/y.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 BASE 26
16 #define BUCKETS 10
17 #define MAX_VALUE 999
18 #define NUM_DIGITS 3
19
20 /*
21 * Author:
22 * Date:
23 * Purpose:
24 * Problem:
25 */
26
27 /*
28 * This template reads data until a terminating value is reached.
29 */
30
31 int num[BUCKETS+1];
32
33 void init()
34 {
35 /* FUNCTION init */
36 int i;
37
38 for (i=0; i<=BUCKETS; i++)
39 {
40 /* for each bucket */
41 num[i] = 0;
42 } /* for each bucket */
43 } /* FUNCTION init */
44
45 void addDigit(int digit)
46 {
47 /* FUNCTION addDigit */
48 int i;
49 int carry;
50
51 for (i=0; i<BUCKETS; i++)
52 {
53 /* for each bucket */
54 num[i] = num[i] * BASE;
55 } /* for each bucket */
56 num[0] = num[0] + digit;
57 for (i=0; i<BUCKETS; i++)
58 {
59 /* for each bucket */
60 if (MAX_VALUE < num[i])
61 {
62 /* we have a carry */
63 carry = num[i] / (MAX_VALUE + 1);
64 num[i] = num[i] % (MAX_VALUE + 1);
65 num[i+1] = num[i+1] + carry;
66 } /* we have a carry */
67 } /* for each bucket */
68 } /* FUNCTION addDigit */
69
70 void dumpNum()
71 {
72 /* FUNCTION dumpNum */
73 int i;
74 int comma = FALSE;
75
76 i = BUCKETS - 1;
77 if (0 < num[i])
78 {
79 /* have to print the first bucket */
80 printf("%d ", num[BUCKETS-1]);
81 comma=TRUE;
82 } /* have to print the first bucket */
83 for (i=(BUCKETS-1); 0<=i; i--)
84 {
85 /* for */
86 if (comma)
87 {
88 /* print regardless of value */
89 printf(",%03d", num[i]);
90 } /* print regardless of value */
91 else if (0 < num[i])
92 {
93 /* time to start printing */
94 printf("%d", num[i]);
95 comma = TRUE;
96 } /* time to start printing */
97 } /* for */
98 } /* FUNCTION dumpNum */
99
100 void dump()
101 {
102 /* FUNCTION dump */
103 } /* FUNCTION dump */
104
105 int getInput()
106 {
107 /* FUNCTION getInput */
108 int dataReadFlag;
109 return (dataReadFlag);
110 } /* FUNCTION getInput */
111
112 void process()
113 {
114 /* FUNCTION process */
115 int i;
116 unsigned long long int t = 1;
117
118 for (i=0; i<21; i++)
119 {
120 /* for */
121 printf("%2d: ", i);
122 dumpNum();
123 printf("\n");
124 addDigit(1);
125 } /* for */
126 } /* FUNCTION process */
127
128 int main ()
129 {
130 /* main */
131 int moreToDo;
132
133 process();
134
135 return EXIT_SUCCESS;
136 } /* main */
137