Many persons are familiar with the Roman numerals for relatively small numbers. The symbols “i”,“v”, “x”, “l”, and “c” represent the decimal values 1, 5, 10, 50, and 100 respectively. To representother values, these symbols, and multiples where necessary, are concatenated, with the smaller-valuedsymbols written further to the right. For example, the number 3 is represented as “iii”, and the value73 is represented as “lxxiii”. The exceptions to this rule occur for numbers having units values of 4or 9, and for tens values of 40 or 90. For these cases, the Roman numeral representations are “iv” (4),“ix” (9), “xl” (40), and “xc” (90). So the Roman numeral representations for 24, 39, 44, 49, and 94are “xxiv”, “xxxix”, “xliv”, “xlix”, and “xciv”, respectively.

The preface of many books has pages numbered with Roman numerals, starting with “i” for thefirst page of the preface, and continuing in sequence. Assume books with pages having 100 or fewerpages of preface. How many “i”, “v”, “x”, “l”, and “c” characters are required to number the pages inthe preface? For example, in a five page preface we’ll use the Roman numerals “i”, “ii”, “iii”, “iv”,and “v”, meaning we need 7 “i” characters and 2 “v” characters.

Input

The input will consist of a sequence of integers in the range 1 to 100, terminated by a zero. For eachsuch integer, except the final zero, determine the number of different types of characters needed tonumber the prefix pages with Roman numerals.

Output

For each integer in the input, write one line containing the input integer and the number of charactersof each type required. The examples shown below illustrate an acceptable format.

Sample Input

1

2

20

99

0

Sample Output

1: 1 i, 0 v, 0 x, 0 l, 0 c

2: 3 i, 0 v, 0 x, 0 l, 0 c

20: 28 i, 10 v, 14 x, 0 l, 0 c

99: 140 i, 50 v, 150 x, 50 l, 10 c

Regionals 1995 >> North America - North Central NA

问题链接:UVA344 UVALive5452 Roman Digititis

问题简述:(略)

问题分析

  根据罗马数字的拼写规则从大到小逐步转换即可。

  然后再做统计。

程序说明:(略)

题记:(略)

参考链接:(略)

AC的C++语言程序如下:

/* UVA344 UVALive5452 Roman Digititis */#include <iostream>using namespace std;int main()
{int n, n2;int i, v, x, l, c;while(cin >> n && n) {i = v = x = l = c = 0;for(int k=1; k<=n; k++) {n2 = k;if(n2 == 100)c++, n2 = 0;if(n2 >= 90)c++, x++, n2 -= 90;if(n2 >= 50)l++, n2 -= 50;if(n2 >= 40)l++, x++, n2 -= 40;x += n2 / 10;n2 %= 10;if(n2 == 9)x++, i++, n2 = 0;if(n2 >= 5)v++, n2 -= 5;if(n2 == 4)v++, i++, n2 = 0;i += n2;}printf("%d: %d i, %d v, %d x, %d l, %d c\n", n, i, v, x, l, c);}return 0;
}

UVA344 UVALive5452 Roman Digititis【Ad Hoc】相关推荐

  1. Bailian4137 最小新整数【Ad Hoc】

    4137:最小新整数 总时间限制: 1000ms 内存限制: 65536kB 描述 给定一个十进制正整数n(0 < n < 1000000000),每个数位上数字均不为0.n的位数为m. ...

  2. Bailian4040 买书问题【Ad Hoc】

    4040:买书问题 总时间限制: 1000ms 内存限制: 65536kB 描述 某网上书店举行优惠促销,现有两种优惠策略.策略一是购书总额大于100元的可享受免费送货.策略二是如果购书数量大于3本, ...

  3. UVA10945 Mother bear【Ad Hoc】

    Unforunately for our lazy "heroes", the nuts were planted by an evil bear known as- Dave, ...

  4. UVA11309 Counting Chaos【Ad Hoc】

    Wolfgang Puck's rival, Emeril Lagasse ("BAM!"), recently set the world culinary record in ...

  5. UVA11942 Lumberjack Sequencing【Ad Hoc】

    Another tale of lumberjacks?. Let see -     The lumberjacks are rude, bearded workers, while foremen ...

  6. UVA11764 Jumping Mario【Ad Hoc】

    Mario is in the final castle. He now needs to jump over few walls and then enter the Koopa's Chamber ...

  7. POJ3359 UVA1209 LA3173 Wordfish【Ad Hoc】

    Wordfish Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1082 Accepted: 535 Description Y ...

  8. POJ2940 HDU1489 UVA11054 Wine Trading in Gergovia【Ad Hoc】

    Wine Trading in Gergovia Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3541   Accepte ...

  9. UVA10189 Minesweeper【Ad Hoc】

    Have you ever played Minesweeper? It's a cute little game which comes within a certain Operating Sys ...

最新文章

  1. Symfony笔记之--控制器的快捷方法
  2. 完整的项目工程目录结构
  3. 输入梯度惩罚与参数梯度惩罚的一个不等式
  4. webpack打包js文件
  5. c语言转汇编语言 vs,C语言转换成汇编语言
  6. Linux下的tree命令 --Linux下目录树查看
  7. Phonegap VS AppCan
  8. 【SQL篇章--CREATE TABLE】
  9. AdobeFlashPlayer:GPU加速原理解析
  10. POI操作Microsoft Office 之 操作PPT简单示例(附源码)
  11. STM32----DMA控制器
  12. 小程序轮播图swiper实现
  13. string split 相关知识
  14. 使用PHP实现蜘蛛访问日志统计
  15. Windows Installer和即点即用版本的Office程序不能并行的问题
  16. java题型_java一些经典题型
  17. json与j对象的关系和与对象的相互转换
  18. 维度、度量与多维数据
  19. 全栈公开课(深入浅出现代Web编程)学习——Part0-Web 应用的基础设施
  20. 31各省首字母排序、国外国家名排序(中文首字母)

热门文章

  1. 十大震撼谷歌地图卫星照
  2. matlab 连通域数量,【Matlab】找到矩阵中每个连通域的最小值
  3. python登录接口测试_接口测试,基于Python
  4. matlab中求方差的,matlab中求方差为什么除以n-1?
  5. Linux软件包管理的知识点,Debian软件包管理APT和存储库的基础知识[Linux 101] | MOS86...
  6. tomcat服务器的虚拟目录,Windows系统下安装Tomcat服务器和配置虚拟目录的方法
  7. linux查看日历_能从远程获得乐趣的 Linux 命令 | Linux 中国
  8. Qt总结之十九:Qt中控件new之后需不需要delete的问题
  9. 最短路径之弗洛伊德算法
  10. 数据挖掘:模型选择——逻辑回归