The Famous Clock

时间限制:1000 ms  |  内存限制:65535 KB
难度:1
 
描述

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.
样例输入
  1. I
  2. II
  3. III
  4. IV
  5. V
  6. VI
  7. VII
  8. VIII
  9. IX
  10. X
  11. XI
  12. XII
样例输出
  1. Case 1: 1
  2. Case 2: 2
  3. Case 3: 3
  4. Case 4: 4
  5. Case 5: 5
  6. Case 6: 6
  7. Case 7: 7
  8. Case 8: 8
  9. Case 9: 9
  10. Case 10: 10
  11. Case 11: 11
  12. Case 12: 12
  1. #include <iostream>
  2. #include <map>
  3. #include <string>
  4. using namespace std;
  5.  
  6. int romanToInt(string s){
  7. int length = s.length();
  8. if (length < ) return ;
  9. map<int,int> romanMap;
  10. romanMap['I'] = ;romanMap['V'] = ;romanMap['X'] = ;
  11. int index = length - , sum = romanMap[s[index]];
  12. while (--index >= ) {
  13. if (romanMap[s[index+]] >romanMap[s[index]]) sum -= romanMap[s[index]];
  14. else sum += romanMap[s[index]];
  15. }
  16. return sum;
  17. }
  18.  
  19. int main(){
  20. int i = ;
  21. string str;
  22. while(cin >> str) cout<<"Case "<<++i<<": "<<romanToInt(str)<<endl;
  23. return ;
  24. }

ACM The Famous Clock的更多相关文章

  1. HDU 4256 The Famous Clock

    The Famous Clock Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  2. nyoj 484-The Famous Clock

    484-The Famous Clock 内存限制:64MB 时间限制:1000ms 特判: No 通过数:2 提交数:2 难度:1 题目描述: Mr. B, Mr. G and Mr. M are ...

  3. 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 ...

  4. 【南阳OJ分类之语言入门】80题题目+AC代码汇总

    小技巧:本文之前由csdn自动生成了一个目录,不必下拉一个一个去找,可通过目录标题直接定位. 本文转载自本人的csdn博客,复制过来的,排版就不弄了,欢迎转载. 声明: 题目部分皆为南阳OJ题目. 代 ...

  5. JavaScript美术馆进化史

    内容选自<<JavaScript DOM 编程艺术>>第4-6章,跟着作者一起见证美术馆的进化吧. 先放效果图,然后一步步做出每个效果.每个效果都有它实用的地方,且知道过程可以 ...

  6. javascript DOM(2) 一个网页上切换显示不同的图片或文本

    摘自: javascript DOM 编程艺术 1. 在一个网页上切换显示不同的图片 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Tran ...

  7. 《DOM Scripting》学习笔记-——第五章、第六章 案列改进

    第四章的案例代码可以得到更好的改进.例如:预留退路.向后兼容性和分离js. 原html代码: <!DOCTYPE html> <html lang="en"> ...

  8. 《DOM Scripting》学习笔记-——第四章 案列分析 JS美术馆(点击链接到图片)

    实现效果:点击图片链接,可以在当前网页显示图片,并且显示图片标题. Html代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN&qu ...

  9. HDU 4256 翻译罗马数字

    参考自:https://www.cnblogs.com/ECJTUACM-873284962/p/6414173.html The Famous Clock Time Limit: 2000/1000 ...

随机推荐

  1. Jquery.Datatables 服务器处理(Server-side processing)

    看了看介绍 http://datatables.club/manual/server-side.html 没有经过处理的分页,先显示出来看看效果,就这样写(存储过程自己写) cshtml " ...

  2. 关于python装饰器(Decorators)最底层理解的一句话

    一个decorator只是一个带有一个函数作为参数并返回一个替换函数的闭包. http://www.xxx.com/html/2016/pythonhexinbiancheng_0718/1044.h ...

  3. [LeetCode] Pow(x, n)

    Implement pow(x, n). 有史以来做过最简单的一题,大概用5分钟ac,我采用fast exponential,这个在sicp的第一章就有描述.思想是:如果n是偶数的话,那么m^n = ...

  4. postgresql设置默认的search_path

    -- Use this to show the current search_path -- Should return: "$user",public SHOW search_p ...

  5. csipsimple,linphone,webrtc比较

    转自: http://www.lxway.com/566299526.htm 最新要做一个移动端视频通话软件,大致看了下现有的开源软件 一) sipdroid1)架构sip协议栈使用JAVA实现,音频 ...

  6. 遍历Map

    Map map = new HashMap(); map.put("1", "value1"); map.put("2", "va ...

  7. 10个很棒的学习Android 开发的网站(转)

    看到江湖旅人 写的<10个很棒的学习iOS开发的网站 - 简书>,所以就忍不住写Android 啦,也希望对大家有帮助.我推荐的网站,都是我在学习Android 开发过程中发现的好网站,给 ...

  8. sp_executesql的用法

    之前做项目的时候负责一个成绩分析的模块儿,写存储过程的时候因为考试的科目是不固定的,所以导致查找成绩的sql语句也是动态的,就用到了sp_executesql,下面就来说一说它的用法 需求:表名是动态 ...

  9. git warning: LF will be replaced by CRLF in...

    如果你有git项目,在提交代码的过程中可能会碰到上面的警告,特别是的项目中包含序列化对象的时候,你可能要小心!! 警告的含义是说换行符的,不同的操作系统的换行符是不一致的,如果你不清楚,真得看看这个 ...

  10. Android学习笔记(一)——安卓开发环境搭建

    安装教程以及资源(2015.11.8最新版):链接:http://pan.baidu.com/s/1kTnOsMr 密码:0ogf