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.

    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到n出现的字母出现了几次,按照权值排序输出

思路,没什么思路,直接模拟

 /*
ID:fffgrdc1
PROB:preface
LANG:C++
*/
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
using namespace std;
char biao[][][]={"","I","II","III","IV","V","VI","VII","VIII","IX",
"","X","XX","XXX","XL","L","LX","LXX","LXXX","XC",
"","C","CC","CCC","CD","D","DC","DCC","DCCC","CM",
"","M","MM","MMM"};
int cnt[];
int trback[]={,'I'-'A','V'-'A','X'-'A','L'-'A','C'-'A','D'-'A','M'-'A'};
int main()
{
freopen("preface.in","r",stdin);
freopen("preface.out","w",stdout);
int n;
memset(cnt,,sizeof(cnt));
scanf("%d",&n);
for(int i=;i<=n;i++)
{
int nn=i;
string ans="";
int bitt=;
while(nn)
{
int temp=nn%;
ans=biao[bitt][temp]+ans;
bitt++;
nn/=;
}
//cout<<ans<<endl;
int len=ans.length();
for(int j=;j<len;j++)
{
cnt[ans[j]-'A']++;
}
}
for(int i=;i<=;i++)
{
if(cnt[trback[i]])
printf("%c %d\n",trback[i]+'A',cnt[trback[i]]);
}
return ;
}

USACO 2.2 Preface Numbering的更多相关文章

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

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

  2. 【USACO 2.2】Preface Numbering (找规律)

    求 1-n 的所有罗马数字表达中,出现过的每个字母的个数. 分别对每个数的罗马表达式计算每个字母个数. 对于十进制的每一位,都是一样的规则,只是代表的字母不同. 于是我们从最后一位往前考虑,当前位由字 ...

  3. USACO Section 2.2: Preface Numbering

    搬了leetcode的代码 /* ID: yingzho1 LANG: C++ TASK: preface */ #include <iostream> #include <fstr ...

  4. USACO Preface Numbering 构造

    一开始看到这道题目的时候,感觉好难 还要算出罗马的规则. 但是仔细一看,数据规模很小, n 只给到3500 看完题目给出了几组样例之后就有感觉了 解题方法就是: n的每个十进制数 转换成相应的罗马数字 ...

  5. Preface Numbering

    链接 分析:先打表需要用到的罗马数字,然后暴力转换,最后统计一下即可 /* PROB:preface ID:wanghan LANG:C++ */ #include "iostream&qu ...

  6. Preface Numbering序言页码

    题面 (preface.pas/c/cpp) 一类书的序言是以罗马数字标页码的.传统罗马数字用单个字母表示特定的数值,以下是标准数字表: I 1 V 5 X 10 L 50 C 100 D 500 M ...

  7. USACO2.2 Preface Numbering【思维+打表】

    这道题乍一看没有什么思路,细看还是没有什么思路 嗯,细看还是可以看出些什么端倪. 不能复合嵌套什么的 总结一下就只有这样3种规则: 1.IXCM最多三个同样连续 加起来2.递减:加起来 注意VLD不连 ...

  8. P1465 序言页码 Preface Numbering (手推)

    题目描述 一类书的序言是以罗马数字标页码的.传统罗马数字用单个字母表示特定的数值,以下是标准数字表: I 1 V 5 X 10 L 50 C 100 D 500 M 1000 最多3个同样的可以表示为 ...

  9. p1465 Preface Numbering

    用这个函数转成罗马数字统计就行了. #include <iostream> #include <cstdio> #include <cmath> #include ...

随机推荐

  1. QlikSense系列(3)——QlikSense建立数据模型

    QlikSense管理数据在帮助中写的比较清楚 https://help.qlik.com/zh-CN/sense/3.1/Subsystems/Hub/Content/LoadData/load-d ...

  2. javascript实现选项卡切换的4种方法

    方法一:for循环+if判断当前点击与自定义数组是否匹配 <html lang="en"> <head> <meta charset="UT ...

  3. go基础笔记

    1.slice:作为参数传递时,传递的是地址,当append时,在新的内存地址分配数据,但是没有返回给原的slice,只能通过返回值的方式赋值给slice2.func(a []int):传递,可以3. ...

  4. mysqldump+mydumper+xtrabackup备份原理流程

    mysqldump备份原理 备份的基本流程如下: 1.调用FTWRL(flush tables with read lock),全局禁止读写 2.开启快照读,获取此时的快照(仅对innodb表起作用) ...

  5. 提示“CD/DVD找不到媒体所需的驱动”

    最近在帮我姐安装win7系统时提 示“CD/DVD找不到媒体所需的驱动”,我用的是U盘安装方式,觉得奇怪,那个镜像文件我已经安装过几十次都没有出错,显然是不会有错的.但是新买的电 脑又不会太大的问题, ...

  6. CaptCha的现状与未来

    2011年的老文.................转自于伯乐在线:http://blog.jobbole.com/4655/       有一个机会,朋友推荐一个创业的哥们给我认识,方向就是验证码识别 ...

  7. 04--深入探讨C++中的引用

    深入探讨C++中的引用           引用是C++引入的新语言特性,是C++常用的一个重要内容之一,正确.灵活地使用引用,可以使程序简洁.高效.我在工作中发现,许多人使用它仅仅是想当然,在某些微 ...

  8. (转)Bootstrap 之 Metronic 模板的学习之路 - (6)自定义和扩展

    https://segmentfault.com/a/1190000006815041 前面我们将 Metronic 的结构和源码大致浏览了一遍,Metronic 整个文件包有三百多兆,在实际项目中, ...

  9. ios 编译版本 最低版本 运行版本 动态链接库

    if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) 运行环境判断: #if __IPHONE_OS_VERSION_ ...

  10. Java中 ArrayList类常用方法和遍历

     ArrayList类对于元素的操作,基本体现在——增.删.查.常用的方法有: public boolean add(E e) :将指定的元素添加到此集合的尾部. public E remove(in ...