03964.com

文档资料库 文档搜索专家

文档资料库 文档搜索专家

【题目描述】

Preface Numbering

A certain book's prefaces are numbered in upper case Roman numerals. Traditional Roman numeral values use a single letter to represent a certain 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 10n may 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 connected together 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 of one 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 from the mark it precedes: IV = 4 IX = 9 XL = 40 This compound mark forms a unit and may not be combined to make another compound mark (e.g., IXL is wrong for 39; XXXIX is correct). Compound marks like XD, IC, and XM are not legal, since the smaller mark is too much smaller than the larger one. For XD (wrong for 490), one would use CDXC; for IC (wrong for 99), one would use XCIX; for XM (wrong for 990), one would use CMXC. 90 is expressed XC and not LXL, since L followed by X connotes that successive marks are X or smaller (probably, anyway). Given N (1 <= N < 3,500), the number of pages in the preface of a book, calculate and print the number of I's, V's, etc. (in order from lowest to highest) required to typeset all the page numbers (in Roman numerals) from 1 through N. Do not print letters that do not appear in the page numbers specified. If N = 5, then the page numbers are: I, II, III, IV, V. The total number of I's is 7 and the total number of V's is 2. 【我的思路】 打个表，把每个位对应数字的对应字母的个数记录下来，要特别注意的是‘9’的统计。 【code】 { ID:yxy07015 PROG:preface

LANG:PASCAL } const di:array[0..9] of integer=(0,1,2,3,1,0,1,2,3,1); dx:array[0..9] of integer=(0,1,2,3,1,0,1,2,3,1); dc:array[0..9] of integer=(0,1,2,3,1,0,1,2,3,1); dm:array[0..9] of integer=(0,1,2,3,1,0,1,2,3,1); dv:array[0..9] of integer=(0,0,0,0,1,1,1,1,1,0); dl:array[0..9] of integer=(0,0,0,0,1,1,1,1,1,0); dd:array[0..9] of integer=(0,0,0,0,1,1,1,1,1,0); var n,s,x:integer; ni,nv,nx,nl,nc,nd,nm:longint; begin assign(input,'preface.in'); reset(input); assign(output,'preface.out'); rewrite(output); readln(n); s:=1; while s<=n do begin x:=s; inc(ni,di[x mod 10]); inc(nv,dv[x mod 10]); if x mod 10=9 then inc(nx); x:=x div 10; inc(nx,dx[x mod 10]); inc(nl,dl[x mod 10]); if x mod 10=9 then inc(nc); x:=x div 10; inc(nc,dc[x mod 10]); inc(nd,dd[x mod 10]); if x mod 10=9 then inc(nm); x:=x div 10; inc(nm,dm[x mod 10]); inc(s); end; if ni>0 then writeln('I ',ni); if nv>0 then writeln('V ',nv); if nx>0 then writeln('X ',nx); if nl>0 then writeln('L ',nl); if nc>0 then writeln('C ',nc); if nd>0 then writeln('D ',nd); if nm>0 then writeln('M ',nm); close(input); close(output); end.

Executing... Test 1: TEST OK [0.003 secs, 276 KB] Test 2: TEST OK [0.003 secs, 276 KB] Test 3: TEST OK [0.003 secs, 276 KB] Test 4: TEST OK [0.003 secs, 276 KB]

Test 5: TEST OK [0.003 secs, 276 KB] Test 6: TEST OK [0.003 secs, 276 KB] Test 7: TEST OK [0.003 secs, 276 KB] Test 8: TEST OK [0.003 secs, 276 KB] All tests OK.

赞助商链接

相关文章:

- 食品专业英语-preface
- 食品专业英语-
*preface*_工学_高等教育_教育专区。*preface*随着食品科学的迅猛发展, 许多国外先进的食品工艺、技术和设备源源不断地被引进, 各种食品信息愈来愈呈现...

- 张红杰设计
- I
*Preface*Building water supply and drainage engineering major is the study of the construction of the internal structure of the water supply and drainage ...

- 电气SHELL壳牌规范33654031
- October 2001 Page 2
*PREFACE*DEPs (Design and Engineering Practice) publications reflect the views, at the time of publication, of: Shell Global Solutions ...

- 拨叉夹具设计说明书
- then be used as the precise basis with the bore that processed.Processing primarily work
*preface*arrangement is first to process a flat surface with the...

- section2.2.1 Preface Numbering
- SECTION2.2.1
*PREFACE*NUMBERING*Preface*Numbering 序言页码译 by Jeru 一类书的序言是以罗马数字标页码的。传统罗马数字用单个字母表示特定的数 值,一下是标准...

- A0本课程Preface
- A0本课程
*Preface*_管理学_高等教育_教育专区。本课程前言一、统领理念: 学生在老师的指导下自主学习,学有所 得。 有下列思想情况的同学,需要预先自 我警惕: 1...

- preface carries on
- Cross a construction to the of each professional cent pack, carry on effective coordination, solve the work interface mutual interference, work
*preface*that...

- preface英国法释义引言
*preface*英国法释义引言 - COMMENTARIES ON THE LAWS OF ENGLAND BOOK THE FIRST. BY WILLIAM BLACKSTONE, Esq....

- ...worked at the task of writing a preface to _答案...
- The two scholars worked at the task of writing a
*preface*to the new dictionary for three hours ______ last night. A. at lengthB. in fullC. ...

- 2The work preface shoulded not expect to start cons...
- 2The work
*preface*shoulded not expect to start construction in rain_英语学习_外语学习_教育专区。2The work*preface*shoulded not expect to start ...

更多相关标签: