博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[解题报告]344 - Roman Digititis
阅读量:6252 次
发布时间:2019-06-22

本文共 2912 字,大约阅读时间需要 9 分钟。

 Roman Digititis 

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 represent other values, these symbols, and multiples where necessary, are concatenated, with the smaller-valued symbols written further to the right. For example, the number 3 is represented as ``iii", and the value 73 is represented as ``lxxiii". The exceptions to this rule occur for numbers having units values of 4 or 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 94 are ``xxiv", ``xxxix", ``xliv", ``xlix", and ``xciv", respectively.

 

The preface of many books has pages numbered with Roman numerals, starting with ``i" for the first page of the preface, and continuing in sequence. Assume books with pages having 100 or fewer pages of preface. How many ``i", ``v", ``x", ``l", and ``c" characters are required to number the pages in the 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 each such integer, except the final zero, determine the number of different types of characters needed to number the prefix pages with Roman numerals.

 

Output

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

 

Sample Input

 

1220990

 

Sample Output

 

1: 1 i, 0 v, 0 x, 0 l, 0 c2: 3 i, 0 v, 0 x, 0 l, 0 c20: 28 i, 10 v, 14 x, 0 l, 0 c99: 140 i, 50 v, 150 x, 50 l, 10 c 题目不难,手打好累。。。。。
#include 
int num_i(int n){ int a=n%5; if(a==4) return 1; else return a;}int num_v(int n) { n%=10; if(n>=4&&n<=8) return 1; else return 0;}int num_x(int n) { n%=50; if (n<=8) return 0; else if(n>=9 && n<=18) return 1; else if(n>=19 && n<=28) return 2; else if(n>=29 && n<=38) return 3; else if(n==39) return 4; else if(n>=40 && n<=48) return 1; else return 2;}int num_l(int n) { if(n>=40 && n<=89) return 1; else return 0; }int num_c(int n){ if(n>=90) return 1; else return 0; }int main(){ int n; int a; while (scanf("%d", &n)!=EOF) { int i=0,v=0,x=0,l=0,c=0; if(n==0) return 0; for (a=1;a<=n; a++) { i+=num_i(a); v+=num_v(a); x+=num_x(a); l+=num_l(a); c+=num_c(a); } printf("%d: %d i, %d v, %d x, %d l, %d c\n",n,i,v,x,l,c); }}

 

转载于:https://www.cnblogs.com/TheLaughingMan/archive/2013/02/25/2932193.html

你可能感兴趣的文章
linux系统常用命令
查看>>
用原始方法解析复杂字符串,json一定要用JsonMapper么?
查看>>
Linux ld命令
查看>>
在 Word 中的受支持的区域设置标识符的列表
查看>>
No package的问题解决
查看>>
【转】chrome浏览器的跨域设置——包括版本49前后两种设置
查看>>
母牛的故事
查看>>
Caffe + Ubuntu 14.04 64bit + CUDA 6.5 配置说明2
查看>>
javaScript基础练习题-下拉框制作
查看>>
基于 OAuth 安全协议的 Java 应用编程1
查看>>
使用Golang利用ectd实现一个分布式锁
查看>>
javaweb学习总结五(内省、beanUtils工具包)
查看>>
An easy to use android color picker library
查看>>
iOS10全新推送功能的实现
查看>>
C#中容易被忽视的细节整理
查看>>
php内核分析(二)-ZTS和zend_try
查看>>
获取form对象
查看>>
不确定人数的抽奖方法
查看>>
win7 windows server 2008R2下 https SSL证书安装的搭配(搭配https ssl本地测试环境)
查看>>
sh脚本——#!/bin/bash
查看>>