/home/toolbox/public_html/solutions/7/706/a1.c
1 #include <stdio.h>
2
3 #define TRUE (1 == 1)
4 #define FALSE (1 != 1)
5
6 #define MAX_VALUES 10
7 #define SEGMENTS 7
8 #define DIGITS 10
9
10 void init(int LCD[][DIGITS])
11 {
12 // BEGIN FUNCTION init
13 int i,j;
14
15 for (i=0; i < SEGMENTS; i++)
16 for (j=0; j< DIGITS; j++)
17 LCD[i][j] = 1;
18
19 // layout of 7-segment LCD
20 // 0
21 // 3 5
22 // 1
23 // 4 6
24 // 2
25
26 // digit 0
27 LCD[1][0] = 0;
28
29 // digit 1
30 LCD[0][1] = 0;
31 LCD[1][1] = 0;
32 LCD[2][1] = 0;
33 LCD[3][1] = 0;
34 LCD[4][1] = 0;
35
36 // digit 2
37 LCD[3][2] = 0;
38 LCD[6][2] = 0;
39
40 // digit 3
41 LCD[3][3] = 0;
42 LCD[4][3] = 0;
43
44 // digit 4
45 LCD[0][4] = 0;
46 LCD[2][4] = 0;
47 LCD[4][4] = 0;
48
49 // digit 5
50 LCD[4][5] = 0;
51 LCD[5][5] = 0;
52
53 // digit 6
54 LCD[5][6] = 0;
55
56 // digit 7
57 LCD[1][7] = 0;
58 LCD[2][7] = 0;
59 LCD[3][7] = 0;
60 LCD[4][7] = 0;
61
62 // digit 8
63
64 // digit 9
65 LCD[4][9] = 0;
66
67 } // BEGIN FUNCTION init
68
69 void printCharacterRow(char a, char b, char c, int s)
70 {
71 // BEGIN FUNCTION printCharacterRow
72 int i;
73
74 printf("%c", a);
75 for (i=0; i < s; i++)
76 printf("%c", b);
77 printf("%c ", c);
78 } // BEGIN FUNCTION printCharacterRow
79
80 int getInput(int *s, int Arr[], int *cnt)
81 {
82 // BEGIN FUNCTION getInput
83 int moreToDo;
84 unsigned long int tmp;
85 int i;
86
87 scanf("%d ", s);
88 if (0 < *s)
89 {
90 // then
91 moreToDo = TRUE;
92 scanf("%d ", &tmp);
93 // number conversion loop
94 for (i=0; 0 < tmp; i++)
95 {
96 // for
97 Arr[i] = tmp % 10;
98 tmp = tmp / 10;
99 } // for
100 *cnt = i;
101 } // then
102 else
103 {
104 // else
105 moreToDo = FALSE;
106 } // else
107 return moreToDo;
108 } // END FUNCTION getInput
109
110 void dump(int s, int Arr[], int cnt)
111 {
112 // BEGIN FUNCTION dump
113 int i;
114
115 printf("S=%d -- Number (%d):", s, cnt);
116 for (i=cnt-1; 0 <= i; i--)
117 printf("%d", Arr[i]);
118 printf("\n");
119 } // END FUNCTION dump
120
121 void printVerticalChar(int val1, int val2, int s)
122 {
123 // BEGIN FUNCTION printVerticalChar
124 char V[2]; // Vertical character
125 V[0] = ' ';
126 V[1] = '|';
127
128 printCharacterRow(V[val1], ' ', V[val2], s);
129 } // END FUNCTION printVerticalChar
130
131 void printHorizontalChar(int val, int s)
132 {
133 // BEGIN FUNCTION printHorizontalChar
134 char H[2]; // Horizontal character
135 H[0] = ' ';
136 H[1] = '-';
137
138 printCharacterRow(' ', H[val], ' ', s);
139 } // END FUNCTION printHorizontalChar
140
141 void printHorizontalRow(int s, int Arr[], int cnt, int LCD[][DIGITS], int row)
142 {
143 // BEGIN FUNCTION printHorizontalRow
144 int i;
145 int j;
146
147 for (i=cnt-1; 0 <= i; i--)
148 {
149 // for
150 printHorizontalChar(LCD[row][Arr[i]], s);
151 } // for
152 printf("\n");
153 } // END FUNCTION printHorizontalRow
154
155 void printVerticalRow(int s, int Arr[], int cnt, int LCD[][DIGITS], int col1, int col2)
156 {
157 // BEGIN FUNCTION printVerticalRow
158 int i;
159 int j;
160
161 for (i=cnt-1; 0 <= i; i--)
162 {
163 // for
164 printVerticalChar(LCD[col1][Arr[i]], LCD[col2][Arr[i]], s);
165 } // for
166 printf("\n");
167 } // END FUNCTION printVerticalRow
168
169
170 void process(int s, int Arr[], int cnt, int LCD[][DIGITS])
171 {
172 // BEGIN FUNCTION process
173 int i;
174
175 // top row
176 printHorizontalRow(s, Arr, cnt, LCD, 0);
177 for (i=0; i<s; i++)
178 printVerticalRow(s, Arr, cnt, LCD, 3, 5);
179 printHorizontalRow(s, Arr, cnt, LCD, 1);
180 for (i=0; i<s; i++)
181 printVerticalRow(s, Arr, cnt, LCD, 4, 6);
182 printHorizontalRow(s, Arr, cnt, LCD, 2);
183 printf("\n");
184 } // END FUNCTION process
185
186 int main ()
187 {
188 // main
189 int moreToDo;
190 int cnt; // number of digits
191 int Arr[MAX_VALUES]; // array of digits
192 int s; // repeat count
193 int LCD[SEGMENTS][DIGITS];
194
195 init(LCD);
196 moreToDo = getInput(&s, Arr, &cnt);
197 while (moreToDo)
198 {
199 // while
200 // dump(s, Arr, cnt);
201 process(s, Arr, cnt, LCD);
202 moreToDo = getInput(&s, Arr, &cnt);
203 } // while
204
205 return 1;
206 } // main
207