/home/toolbox/public_html/solutions/3/344/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 /*
16 * Author: Isaac Traxler
17 * Date: 2021-01-11
18 * Purpose: fun
19 * Problem: 344 - Roman Digititis
20 */
21
22 /*
23 * This template reads data until a terminating value is reached.
24 */
25
26 #define MAX_CACHE 102
27 #define I 0
28 #define V 1
29 #define X 2
30 #define L 3
31 #define C 4
32
33 int count[MAX_CACHE][5];
34 int num;
35
36 void init()
37 {
38 /* FUNCTION init */
39 int i;
40 int j;
41
42 /* zero everything out */
43 for (i=0; 101>i; i++)
44 {
45 /* for i */
46 count[i][I] = 0;
47 count[i][V] = 0;
48 count[i][X] = 0;
49 count[i][L] = 0;
50 count[i][C] = 0;
51 } /* for i */
52 /* set first 10 (single digit numbers) */
53 /* 1 - i */ count[1][I] = 1;
54 /* 2 - ii */ count[2][I] = 2;
55 /* 3 - iii */ count[3][I] = 3;
56 /* 4 - iv */ count[4][I] = 1;
57 count[4][V] = 1;
58 /* 5 - v */ count[5][V] = 1;
59 /* 6 - vi */ count[6][I] = 1;
60 count[6][V] = 1;
61 /* 7 - vii */ count[7][I] = 2;
62 count[7][V] = 1;
63 /* 8 - viii */ count[8][I] = 3;
64 count[8][V] = 1;
65 /* 9 - ix */ count[9][I] = 1;
66 count[9][X] = 1;
67
68 /* set each multiple of 10 */
69 /* 10 - x */ count[10][X] = 1;
70 /* 20 - xx */ count[20][X] = 2;
71 /* 30 - xxx */ count[30][X] = 3;
72 /* 40 - xl */ count[40][X] = 1;
73 count[40][L] = 1;
74 /* 50 - l */ count[50][L] = 1;
75 /* 60 - lx */ count[60][X] = 1;
76 count[60][L] = 1;
77 /* 70 - lxx */ count[70][X] = 2;
78 count[70][L] = 1;
79 /* 80 - lxxx */ count[80][X] = 3;
80 count[80][L] = 1;
81 /* 90 - xc */ count[90][X] = 1;
82 count[90][C] = 1;
83 /* 100 - c */ count[100][C] = 1;
84 /* fill in gaps */
85 for (i=0; 10>i; i++)
86 {
87 /* for i */
88 for (j=10; 101>j; j=j+10)
89 {
90 /* for each j */
91 count[j+i][I] = count[i][I] + count[j][I];
92 count[j+i][V] = count[i][V] + count[j][V];
93 count[j+i][X] = count[i][X] + count[j][X];
94 count[j+i][L] = count[i][L] + count[j][L];
95 count[j+i][C] = count[i][C] + count[j][C];
96 } /* for each j */
97 } /* for i */
98 /* now do accumulations */
99 for (i=1; 100>i; i++)
100 {
101 /* for i */
102 j = i + 1;
103 count[j][I] = count[j][I] + count[i][I];
104 count[j][V] = count[j][V] + count[i][V];
105 count[j][X] = count[j][X] + count[i][X];
106 count[j][L] = count[j][L] + count[i][L];
107 count[j][C] = count[j][C] + count[i][C];
108 } /* for i */
109
110 } /* FUNCTION init */
111
112 void dump()
113 {
114 /* FUNCTION dump */
115 } /* FUNCTION dump */
116
117 int getInput()
118 {
119 /* FUNCTION getInput */
120 int dataReadFlag;
121
122 scanf(" %d ", &num);
123 dataReadFlag = (0 < num);
124 return (dataReadFlag);
125 } /* FUNCTION getInput */
126
127 void process()
128 {
129 /* FUNCTION process */
130 printf("%d: %d i, %d v, %d x, %d l, %d c\n", num, count[num][I], count[num][V], count[num][X], count[num][L], count[num][C]);
131 } /* FUNCTION process */
132
133 int main()
134 {
135 /* main */
136 int moreToDo;
137
138 init();
139 moreToDo = getInput();
140 while (moreToDo)
141 {
142 /* while */
143 process();
144 moreToDo = getInput();
145 } /* while */
146
147 return EXIT_SUCCESS;
148 } /* main */
149