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;}
- UVa 344 Roman Digititis (罗马数字统计)
- UVa 344 - Roman Digititis
- Roman number -- 罗马数字
- 罗马数字加法实现Roman Calculator
- Integer to Roman (罗马数字转换)
- Integer to Roman (罗马数字转换) 【leetcode】
- Roman to Integer 罗马数字转阿拉伯数字@LeetCode
- Integer to Roman 阿拉伯数字转罗马数字@LeetCode
- LeetCode Integer to Roman数字转成罗马数字
- LeetCode Roman to Integer 罗马数字转阿拉伯数字
- Integer to Roman 整数转换成罗马数字
- Roman to Integer 罗马数字转换成整数
- Integer to Roman (整数转为罗马数字)
- [LeetCode]-Integer to Roman 阿拉伯数字转罗马数字
- Roman to Integer 罗马数字转为整数
- Integer to Roman 整数转罗马数字
- Roman to Integer 罗马数字转化为整数
- [LeetCode]Integer to Roman整数转罗马数字
- kafka第六篇---多个进程读不齐
- IOS高访微信聊天对话界面(sizeWithFont:constrainedToSize和stretchableImageWithLeftCapWidth的使用)
- AndroidMenifest.xml中minSdkVersion、targetSdkVersion、targetApiLevel的区别
- shell
- 让文字在div中垂直居中显示
- UVa 344 Roman Digititis (罗马数字统计)
- FFT结果的物理意义
- db2 中通过查询结果来create table 的3种方式
- PHP 设计模式之单例模式
- Linux:黑客传说
- CPE常用指令
- FFT与DCT物理意义
- 【转】 java时钟的实现
- BugFree Excel格式化VBA实现