您的位置:首页 > 其它

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++语言程序如下:

/* 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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: