ACM The Famous Clock
The Famous Clock
- 描述
-
Mr. B, Mr. G and Mr. M are now in Warsaw, Poland, for the 2012’s ACM-ICPC World Finals Contest. They’ve decided to take a 5 hours training every day before the contest. Also, they plan to start training at 10:00 each day since the World Final Contest will do so. The scenery in Warsaw is so attractive that Mr. B would always like to take a walk outside for a while after breakfast. However, Mr. B have to go back before training starts, otherwise his teammates will be annoyed. Here is a problem: Mr. B does not have a watch. In order to know the exact time, he has bought a new watch in Warsaw, but all the numbers on that watch are represented in Roman Numerals. Mr. B cannot understand such kind of numbers. Can you translate for him?
- 输入
- Each test case contains a single line indicating a Roman Numerals that to be translated. All the numbers can be found on clocks. That is, each number in the input represents an integer between 1 and 12. Roman Numerals are expressed by strings consisting of uppercase ‘I’, ‘V’ and ‘X’. See the sample input for further information.
- 输出
- For each test case, display a single line containing a decimal number corresponding to the given Roman Numerals.
- 样例输入
-
I
II
III
IV
V
VI
VII
VIII
IX
X
XI
XII - 样例输出
-
Case 1: 1
Case 2: 2
Case 3: 3
Case 4: 4
Case 5: 5
Case 6: 6
Case 7: 7
Case 8: 8
Case 9: 9
Case 10: 10
Case 11: 11
Case 12: 12#include <iostream>
#include <map>
#include <string>
using namespace std; int romanToInt(string s){
int length = s.length();
if (length < ) return ;
map<int,int> romanMap;
romanMap['I'] = ;romanMap['V'] = ;romanMap['X'] = ;
int index = length - , sum = romanMap[s[index]];
while (--index >= ) {
if (romanMap[s[index+]] >romanMap[s[index]]) sum -= romanMap[s[index]];
else sum += romanMap[s[index]];
}
return sum;
} int main(){
int i = ;
string str;
while(cin >> str) cout<<"Case "<<++i<<": "<<romanToInt(str)<<endl;
return ;
}
ACM The Famous Clock的更多相关文章
- HDU 4256 The Famous Clock
The Famous Clock Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- nyoj 484-The Famous Clock
484-The Famous Clock 内存限制:64MB 时间限制:1000ms 特判: No 通过数:2 提交数:2 难度:1 题目描述: Mr. B, Mr. G and Mr. M are ...
- The Famous Clock
描述 Mr. B, Mr. G and Mr. M are now in Warsaw, Poland, for the 2012’s ACM-ICPC World Finals Contest. T ...
- 【南阳OJ分类之语言入门】80题题目+AC代码汇总
小技巧:本文之前由csdn自动生成了一个目录,不必下拉一个一个去找,可通过目录标题直接定位. 本文转载自本人的csdn博客,复制过来的,排版就不弄了,欢迎转载. 声明: 题目部分皆为南阳OJ题目. 代 ...
- JavaScript美术馆进化史
内容选自<<JavaScript DOM 编程艺术>>第4-6章,跟着作者一起见证美术馆的进化吧. 先放效果图,然后一步步做出每个效果.每个效果都有它实用的地方,且知道过程可以 ...
- javascript DOM(2) 一个网页上切换显示不同的图片或文本
摘自: javascript DOM 编程艺术 1. 在一个网页上切换显示不同的图片 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Tran ...
- 《DOM Scripting》学习笔记-——第五章、第六章 案列改进
第四章的案例代码可以得到更好的改进.例如:预留退路.向后兼容性和分离js. 原html代码: <!DOCTYPE html> <html lang="en"> ...
- 《DOM Scripting》学习笔记-——第四章 案列分析 JS美术馆(点击链接到图片)
实现效果:点击图片链接,可以在当前网页显示图片,并且显示图片标题. Html代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN&qu ...
- HDU 4256 翻译罗马数字
参考自:https://www.cnblogs.com/ECJTUACM-873284962/p/6414173.html The Famous Clock Time Limit: 2000/1000 ...
随机推荐
- 字符识别(模板匹配&BP神经网络训练)
http://blog.csdn.net/zhang11wu4/article/details/7585632
- 让那些为Webkit优化的网站也能适配IE10(转载)
转载地址:http://www.w3cplus.com/css3/adapting-your-webkit-optimized-site-for-internet-explorer-10.html 特 ...
- Delphi函数指针
参考:http://blog.chinaunix.net/uid-91034-id-2009700.html http://blog.csdn.net/procedure1984/article/de ...
- BAT批量处理 命令
第一章 批处理基础第一节 常用批处理内部命令简介 批处理定义:顾名思义,批处理文件是将一系列命令按一定的顺序集合为一个可执行的文本文件,其扩展名为BAT或者CMD.这些命令统称批处理命令.小知识:可以 ...
- 2-01SQL的概述
SQL: Structured Query Languaage:结构化查询语言. 美国国家标准局ANSI. 国际标准化组织. T-SQL: Transact-SQL. T-SQL是SQL的扩展集. 对 ...
- Win10 AppBar
<Page.BottomAppBar> <CommandBar x:Name="cmdBar" Background="Transparent" ...
- 系统调用方式文件编程,王明学learn
系统调用方式文件编程 一.文件描述符 在Linux系统中,所有打开的文件也对应一个数字,这个数字由系统来分配,我们称之为:文件描述符. 二.函数学习 2.1打开文件 open 2.1.2 函数原形 ...
- 提升 LaTeX 效率的小工具:Detexify LaTeX handwritten symbol recognition
Detexify LaTeX handwritten symbol recognition 用 LaTeX 的人找符号的表示方法通常很费事,需要去翻长长的列表.Detexify 是一个省事的小网站,只 ...
- WINDOWS页式内存管理解析
jpg 改 rar
- Emacs 之查看帮助
// */ // ]]> Emacs 之查看帮助 Table of Contents 1. Emacs 入门 1.1. 查看简单的帮助 1.2. 执行elisp代码 1 Emacs 入门 ...