UVA344 UVALive5452 Roman Digititis【Ad Hoc】
2018-02-01 08:02
471 查看
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 representother values, these symbols, and multiples where necessary,
are concatenated, with the smaller-valuedsymbols written further to the right. For example, the number 3 is represented as “iii”, and the value73 is represented as “lxxiii”. The exceptions to this rule occur for numbers having units values of 4or 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 94are “xxiv”, “xxxix”, “xliv”, “xlix”, and “xciv”, respectively.
The preface of many books has pages numbered with Roman numerals, starting with “i” for thefirst page of the preface, and continuing in sequence. Assume books with pages having 100 or fewerpages of preface. How many “i”, “v”, “x”, “l”, and “c” characters
are required to number the pages inthe 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 eachsuch integer, except the final zero, determine the number of different types of characters needed tonumber the prefix pages with Roman numerals.
Output
For each integer in the input, write one line containing the input integer and the number of charactersof each type required. The examples shown below illustrate an acceptable format.
Sample Input
1
2
20
99
0
Sample Output
1: 1 i, 0 v, 0 x, 0 l, 0 c
2: 3 i, 0 v, 0 x, 0 l, 0 c
20: 28 i, 10 v, 14 x, 0 l, 0 c
99: 140 i, 50 v, 150 x, 50 l, 10 c
Regionals 1995 >> North
America - North Central NA
问题链接:UVA344 UVALive5452 Roman Digititis
问题简述:(略)
问题分析:
根据罗马数字的拼写规则从大到小逐步转换即可。
然后再做统计。
程序说明:(略)
题记:(略)
参考链接:(略)
AC的C++语言程序如下:
are concatenated, with the smaller-valuedsymbols written further to the right. For example, the number 3 is represented as “iii”, and the value73 is represented as “lxxiii”. The exceptions to this rule occur for numbers having units values of 4or 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 94are “xxiv”, “xxxix”, “xliv”, “xlix”, and “xciv”, respectively.
The preface of many books has pages numbered with Roman numerals, starting with “i” for thefirst page of the preface, and continuing in sequence. Assume books with pages having 100 or fewerpages of preface. How many “i”, “v”, “x”, “l”, and “c” characters
are required to number the pages inthe 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 eachsuch integer, except the final zero, determine the number of different types of characters needed tonumber the prefix pages with Roman numerals.
Output
For each integer in the input, write one line containing the input integer and the number of charactersof each type required. The examples shown below illustrate an acceptable format.
Sample Input
1
2
20
99
0
Sample Output
1: 1 i, 0 v, 0 x, 0 l, 0 c
2: 3 i, 0 v, 0 x, 0 l, 0 c
20: 28 i, 10 v, 14 x, 0 l, 0 c
99: 140 i, 50 v, 150 x, 50 l, 10 c
Regionals 1995 >> North
America - North Central NA
问题链接:UVA344 UVALive5452 Roman Digititis
问题简述:(略)
问题分析:
根据罗马数字的拼写规则从大到小逐步转换即可。
然后再做统计。
程序说明:(略)
题记:(略)
参考链接:(略)
AC的C++语言程序如下:
/* UVA344 UVALive5452 Roman Digititis */ #include <iostream> using namespace std; int main() { int n, n2; int i, v, x, l, c; while(cin >> n && n) { i = v = x = l = c = 0; for(int k=1; k<=n; k++) { n2 = k; if(n2 == 100) c++, n2 = 0; if(n2 >= 90) c++, x++, n2 -= 90; if(n2 >= 50) l++, n2 -= 50; if(n2 >= 40) l++, x++, n2 -= 40; x += n2 / 10; n2 %= 10; if(n2 == 9) x++, i++, n2 = 0; if(n2 >= 5) v++, n2 -= 5; if(n2 == 4) v++, i++, n2 = 0; i += n2; } printf("%d: %d i, %d v, %d x, %d l, %d c\n", n, i, v, x, l, c); } return 0; }
相关文章推荐
- UVa 344 - Roman Digititis
- UVALive 7139 Rotation
- 【UVALive】3029.City Game<C++>
- UVALive - 7511 Multiplication Table (模拟)
- UVALive - 3942 Remember the Word
- uvalive 3135
- 【UVALive】2145 - Lost in Space(数学)
- uvalive 3644(并查集)
- UvaLive 6663 Count the Regions 离散化+DFS
- UVALive 4639 - Separate Points
- uvalive 4108(线段树)
- UVALive 5733|Iterated Difference|暴力
- UVALive - 5052 Genome Evolution
- UVALive - 3266 Tian Ji -- The Horse Racing
- uvalive 3218
- UVALive 6921 Refraction(二分)
- UVALive 7661 The Size of the Smallest Hole(dfs)
- UVALive2678 UVA1121 Subsequence【前缀和+二分搜索+尺取法】
- UVALive3638 UVA12100 POJ3125 HDU1972 Printer Queue【队列+模拟】
- UVALive 6042 Bee Tower(DP)