题目描述:

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  1000V   5     C  100X  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.

    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 appears on preface page numbers. Stop printing letter totals after printing the highest value letter used to form preface numbers in the specified set.

    SAMPLE OUTPUT (file preface.out)

    I 7
    V 2
    
    题目分析:
  • 这个题目自认为是一道找规律的题目,只需要写一下
  • 1,2,3,4,,,,8,9
  • 10,20,30,40,,,,80,90
  • 100,200,300,,,,800,900
  • 1000,2000,3000
  • 写完这些罗马数字之后就可以立刻找到规律。
#include <iostream>
#include<fstream>
#include<cstring>using namespace std;ifstream infile;
ofstream outfile;int c[10];
int add[10][3] = {{14,5,1},{1,0,0},{2,0,0},{3,0,0},{1,1,0},{0,1,0},{1,1,0},{2,1,0},{3,1,0},{1,0,1}};
int n;
int num[4][10];
char cha[10] = {'I','V','X','L','C','D','M'};void print();
void initNum();
void calcu();
int main(){infile.open("preface.in");outfile.open("preface.out");memset(num,0,sizeof(num));memset(c,0,sizeof(c));infile>>n;initNum();calcu();print();}void initNum(){for(int i=1;i<=n;i++){int t = i;int index = 0;while(t){num[index++][t%10]++;t/=10;}}
}void calcu(){for(int i=0;i<4;i++){int w = i*2;for(int j=1;j<=9;j++){for(int k = 0;k<3;k++)c[k+w]+=add[j][k]*num[i][j];}}}
void print(){for(int i=0;i<7;i++)if(c[i]!=0){outfile<<cha[i]<<" "<<c[i]<<endl;}}

转载于:https://www.cnblogs.com/liushang0419/archive/2012/06/08/2542577.html

USACO 2.3.3 罗马数字相关推荐

  1. USACO Section2.2 Preface Numbering 解题报告 【icedream61】

    preface解题报告 ---------------------------------------------------------------------------------------- ...

  2. USACO:2.2.1 Preface Numbering 序言页码

    USACO:2.2.1 Preface Numbering 序言页码 一.题目描述 ★Preface Numbering 序言页码 一类书的序言是以罗马数字标页码的.传统罗马数字用单个字母表示特定的数 ...

  3. usaco Shaping Regions

    这就是usaco 前面的windows area的变形. /* ID:jinbo wu TASK:rect1 LANG:C++ */ #include<iostream> #include ...

  4. usaco Postal Vans(dp)

    是哈密顿回路,然后...就不知道怎么写了 ,以前写过类似的不过情况没这么多也没这么复 usaco training 6.1.1 Postal Vans 题解 标签: usaco training题解d ...

  5. usaco Beef McNuggets

    这两天贼烦,ccf炸了,还有一个烦心事.哎我都不知道自己能不能坚持下去了.马上期末考了.这段时间还是抓紧时间复习吧同时刷usaco的节奏要跟以前一样了,毕竟课少了. 题解: 只要你知道以下的数论结论, ...

  6. usaco前两章小结

    usaco 暑假老师有推荐做但是那个题目太长了,而且·大部分都是废话做起来特别慢,而且当时自己基本上什么都不懂,太难了所以看了题解做了两题就放弃了. 转眼就上学了,因为想学习acm所以就胡乱找题做但是 ...

  7. usaco ★Fractions to Decimals 分数化小数

    ★Fractions to Decimals 分数化小数 写一个程序,输入一个形如 N/D 的分数(N 是分子,D 是分母),输出它的小数形式. 如果小数有循环节的话,把循环节放在一对圆括号中.例如, ...

  8. usaco ★Bessie Come Home 回家

    ★Bessie Come Home 回家 现在是晚餐时间,而母牛们在外面分散的牧场中. 农民约翰按响了电铃,所以她们开始向谷仓走去. 你的工作是要指出哪只母牛会最先到达谷仓(在给出的测试数据中,总会有 ...

  9. usaco Preface Numbering 序言页码

    Preface Numbering 序言页码 一类书的序言是以罗马数字标页码的.传统罗马数字用单个字母表示特定的数值,一下是标准数字 表: I 1 L 50 M 1000 V 5 C 100 X 10 ...

最新文章

  1. [收藏] Java 编程的动态性
  2. DirectX 向量点乘和叉乘
  3. Java当中的常量池
  4. 利用Skywalking-netcore监控你的应用性能
  5. SQLAlchemy基本使用(Flask中)
  6. 数据库 linux 编译,部署mariadb数据库到linux(源码编译安装)
  7. 2010头号病毒追杀令——恶意下载者001
  8. 千万58招聘人员的选择值得信赖-米苏 58自动循环发帖器V9.03
  9. IBM ServerGuide引导安装指南
  10. 【全网世界区划最全整理输出之第二部分】全世界所有国家的行政区划整理,省市信息,已按照国家,省,市排好序,可直接复制使用,第二部分到8167行,总条数:21088
  11. Android 静默安装
  12. 技术年货:美团技术沙龙合辑大放送
  13. HTML5期末大作业:关于家乡介绍的HTML网页设计——郑州美景HTML+CSS(5页) 学生DW家乡介绍网页设计作业成品 web课程设计网页规划与设计
  14. 带本科生做毕设是什么样的体验,看看学生是怎么评价我的
  15. 文章集合--作者篇--上【转】
  16. 基于JAVA蔚蓝在线学习平台计算机毕业设计源码+数据库+lw文档+系统+部署
  17. Flask+ZUI 开发小型工具网站(二)——ZUI
  18. iphone图片编辑画笔_iPhone手机怎么编辑图片?还不知道的话真的要了解一波了~...
  19. 平台商家面临“血本无归”风险,你真的了解电商二清吗
  20. MATLAB实现支持向量机SVM分类简介

热门文章

  1. yii2 获取同一个账号登录的所有session_前端登录方案?这一篇就够了
  2. 指针 是否相同_c专题之指针---野指针和空指针解析
  3. android 程序闪退 log,写了一个android小程序,测试的时候闪退,然鹅log并没有报错...
  4. .dat文件写入byte类型数组_深入浅出MATLAB数据处理之文件读写
  5. android 打包提示 Password verification failed
  6. 一种神经元探索系统方法及装置
  7. 重新认识HBase,Cassandra列存储——本质是还是行存储,只是可以动态改变列(每行对应的数据字段)数量而已,当心不是parquet...
  8. windows 同时安装 python2 python3
  9. 【思维导图总结——数据库系统概论】绪论
  10. DISK 100% BUSY,谁造成的?(ok)