# 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 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.

2018 年终工作总结及计划 汇报人:张三 职务:行政总监 前言 PREFACE 光阴如梭,2017 的工作转瞬又将成为历史,今天提交这个工作总结,我 多想骄傲自豪地说一声:“一份...

It helps when I preface our sessions with the mention that tens of thousands of dollars go into every second of media they see, that stars have ...
A study of English learning styles of senior high school ...
【Key words】high school English; teaching style; research Preface: With the development of the times and the reform of the curriculum standards, high ...

9.A Preface to Murder
A Preface to Murder Sometimes truth is stranger than fiction. Sometimes life deals a bad hand. Sometimes it is hard to go on. Sometimes evil triumphs...
USACO代码解析Preface Numbering (preface)
[编辑]格式 PROGRAM NAME: preface INPUT FORMAT: (preface.in) 一个整数 N。 OUTPUT FORMAT: (preface.out) 每行一个字符和一个数字 k,表示这个字符出现了 ...
Preface of Moment in Peking
Here is the preface of the novel, if u want to get more following chapters, please contact me.隐藏>> TO BRAVE SOLDIERS OF CHINA WHO ARE LYING DOWN...
A0本课程Preface
A0本课程Preface 隐藏>> 本课程前言一、统领理念: 学生在老师的指导下自主学习,学有所 得。 有下列思想情况的同学,需要预先自 我警惕: 1、完全不愿意自学,只...
Preface to the revised edition
Preface to the revised edition_英语学习_外语学习_教育专区 暂无评价|0人阅读|0次下载|举报文档Preface to the revised edition_英语学习_外语学习_教育专区。...