2.2 preface
来源:互联网 发布:最好用的浏览器 知乎 编辑:程序博客网 时间:2024/04/27 17:39
好久没做题了,坚持!
Preface NumberingA certain book's prefaces are numbered in upper case Roman numerals.Traditional Roman numeral values use a single letter to represent acertain subset of decimal numbers. Here is the standard set:
I 1 L 50 M 1000
V 5 C 100
X 10 D 500
As many as three of the same marks that represent 10nmay be placed consecutively to form other numbers:
- III is 3
- CCC is 300
Marks that have the value 5x10n are never used consecutively.
Generally (with the exception of the next rule), marks are connectedtogether and written in descending order to form even more numbers:
CCLXVIII = 100+100+50+10+5+1+1+1 = 268
Sometimes, a mark that represents 10^n is placed before a mark ofone of the two next higher values (I before V or X; X before L or C;etc.). In this case, the value of the smaller mark is SUBTRACTED fromthe mark it precedes:
- IV = 4
- IX = 9
- XL = 40
This compound mark forms a unit and may not be combined to makeanother compound mark (e.g., IXL is wrong for 39; XXXIX is correct).
Compound marks like XD, IC, and XM are not legal, since thesmaller mark is too much smaller than the larger one. For XD (wrongfor 490), one would use CDXC; for IC (wrong for 99), one would useXCIX; for XM (wrong for 990), one would use CMXC. 90 is expressedXC and not LXL, since L followed by X connotes that successive marksare X or smaller (probably, anyway).
Given N (1 <= N < 3,500), the number of pages in thepreface of a book, calculate and print the number of I's, V's, etc. (inorder from lowest to highest) required to typeset all the page numbers(in Roman numerals) from 1 through N. Do not print letters that do notappear in the page numbers specified.
If N = 5, then the page numbers are: I, II, III, IV, V. The totalnumber of I's is 7 and the total number of V's is 2.
PROGRAM NAME: preface
INPUT FORMAT
A single line containing the integer N.
SAMPLE INPUT (file preface.in)
5
OUTPUT FORMAT
The output lines specify, in ascending order of Roman numeral letters,the letter, a single space, and the number of times that letter appearson preface page numbers. Stop printing letter totals after printingthe highest value letter used to form preface numbers in the specifiedset.
SAMPLE OUTPUT (file preface.out)
I 7
V 2
- 2.2 preface
- USACO 2.2 Preface Numbering (preface)
- Section 2.2 Preface Numbering
- SECTION 2.2 Preface Numbering
- 2.2Preface Numbering
- 2.2.1---Preface Numbering
- USACO 2.2 Preface Numbering
- usaco 2.2.1 preface
- USACO 2.2 Preface Numbering
- Preface
- Preface
- Preface
- Preface
- Preface
- Preface
- preface
- preface
- preface
- 程序员为你的将来定位学习的方向(转载)
- XML-RPC
- 对线程、互斥、同步、信号量的内在关联性的简单讨论
- DBCS下的中文截断处理
- 技术与艺术的结合
- 2.2 preface
- java 实现目录内内容压缩 zip
- EXTJS 开发工具大全
- SECATT启动模式缺失
- 基于QT4的一个多线程工程实现
- say thanks first
- vim与windows/linux之间的复制粘贴小结
- 在VC9.0中实现C++模板类头文件和实现文件分离的方法
- iphone中得到字符串所占空间的大小