UVa 344 Roman Digititis (罗马数字统计)

来源:互联网 发布:Ubuntu更新语言包命令 编辑:程序博客网 时间:2024/06/07 17:45

344 - Roman Digititis

Time limit: 3.000 seconds 

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=280

Many persons are familiar with the Roman numerals for relatively small numbers. The symbols ``i", ``v", ``x", ``l", and ``c" represent the decimal values 1, 5, 10, 50, and 100 respectively. To represent other values, these symbols, and multiples where necessary, are concatenated, with the smaller-valued symbols written further to the right. For example, the number 3 is represented as ``iii", and the value 73 is represented as ``lxxiii". The exceptions to this rule occur for numbers having units values of 4 or 9, and for tens values of 40 or 90. For these cases, the Roman numeral representations are ``iv" (4), ``ix" (9), ``xl" (40), and ``xc" (90). So the Roman numeral representations for 24, 39, 44, 49, and 94 are ``xxiv", ``xxxix", ``xliv", ``xlix", and ``xciv", respectively.

The preface of many books has pages numbered with Roman numerals, starting with ``i" for the first page of the preface, and continuing in sequence. Assume books with pages having 100 or fewer pages of preface. How many ``i", ``v", ``x", ``l", and ``c" characters are required to number the pages in the preface? For example, in a five page preface we'll use the Roman numerals ``i", ``ii", ``iii", ``iv", and ``v", meaning we need 7 ``i" characters and 2 ``v" characters.

Input

The input will consist of a sequence of integers in the range 1 to 100, terminated by a zero. For each such integer, except the final zero, determine the number of different types of characters needed to number the prefix pages with Roman numerals.

Output

For each integer in the input, write one line containing the input integer and the number of characters of each type required. The examples shown below illustrate an acceptable format.

Sample Input

1220990

Sample Output

1: 1 i, 0 v, 0 x, 0 l, 0 c2: 3 i, 0 v, 0 x, 0 l, 0 c20: 28 i, 10 v, 14 x, 0 l, 0 c99: 140 i, 50 v, 150 x, 50 l, 10 c

想了很多方案,最终觉得用switch对9个个位数和9个十位数处理最方便。


完整代码:

/*0.016s*/#include<bits/stdc++.h>using namespace std;int i[105], v[105], x[105], l[105], c[105];int main(){int n, t;for (t = 1; t <= 100; ++t){switch (t / 10){case 1:++x[t];break;case 2:x[t] += 2;break;case 3:x[t] += 3;break;case 4:++x[t], ++l[t];break;case 5:++l[t];break;case 6:++x[t], ++l[t];break;case 7:x[t] += 2, ++l[t];break;case 8:x[t] += 3, ++l[t];break;case 9:++x[t], ++c[t];}switch (t % 10){case 1:++i[t];break;case 2:i[t] += 2;break;case 3:i[t] += 3;break;case 4:++i[t], ++v[t];break;case 5:++v[t];break;case 6:++i[t], ++v[t];break;case 7:i[t] += 2, ++v[t];break;case 8:i[t] += 3, ++v[t];break;case 9:++x[t], ++i[t];}if (t == 100) ++c[t];i[t] += i[t - 1], v[t] += v[t - 1], x[t] += x[t - 1], l[t] += l[t - 1], c[t] += c[t - 1];}while (scanf("%d", &n), n)printf("%d: %d i, %d v, %d x, %d l, %d c\n", n, i[n], v[n], x[n], l[n], c[n]);return 0;}

原创粉丝点击