当前位置:首页 >> 学科竞赛 >>

preface


【题目描述】

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 s

ubset 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 Thermodynamics, the study of energy and its transformations, is applicable to all fields of science and engineering. The text for a basic course ...
preface
TWENTY YEARS AT HULL-HOUSE BY JANE ADDAMS HULL-HOUSE, CHICAGO TO THE MEMORY OF MY FATHER PREFACE Every preface is, I imagine, written after the book...
preface
Preface 23页 免费 PREFACE 2页 1下载券 Preface 26页 免费 Preface 暂无评价 2页 ¥1.00 PREFACE PREFACE 99页 免费 00.Preface 11页 1下载券 0-...
PREFACE-1
PREFACE TO THE THIRD EDITION. OCTOBER 1814. To this slight attempt at a sketch of ancient Scottish manners the public have been more favourable than the...
Preface
Preface Market segmentation aims to a) indentify groups of customers with similar needs and purchasing behavior, allocating them to market segments; b)...
Preface
PREFACE 2页 2财富值 Preface 26页 免费 Preface 暂无评价 2页 1.00元 PREFACE PREFACE 99页 免费 00.Preface 11页 1财富值 0-preface 18页 2财富值 4 ...
Preface
Preface 暂无评价 2页 1.00元 PREFACE PREFACE 99页 免费 00.Preface 11页 1财富值 0-preface 18页 2财富值 4 PREFACE 255页 免费 Preface ix 137页 ...
Preface
第一章+绪论【Preface】 23页 免费 ii Preface 129页 免费如要投诉违规内容,请到百度文库投诉中心;如要提出功能问题或意见建议,请点击此处进行反馈。...
preface
Preface 23页 免费 PREFACE 2页 2财富值 Preface 26页 免费 Preface 暂无评价 2页 1.00元 PREFACE PREFACE 99页 免费 00.Preface 11页 1财富值 0-preface...
Preface and Content
Preface and Content_经管营销_专业资料。preface2010 中国对外贸易百强企业 CHINA’S TOP FOREIGN TRADE ENTERPRISES 中国对外经济贸易统计学会编 Compiled by ...
更多相关标签:
preface是什么意思 | face | 最长的英文单词 | 有道词典 | 拓词 | preface dave liang | surface | preface歌词 |