题目意思:罗马数字转int

思路:字符串从最后一位开始读,IV:+5-1

 class Solution {
public:
int romanToInt(string s) {
map<char,int> mymap;
mymap['I']=;
mymap['V']=;
mymap['X']=;
mymap['L']=;
mymap['C']=;
mymap['D']=;
mymap['M']=;
int ans=mymap[s[s.size()-]];
for(int i=s.size()-;i>=;--i){
if(mymap[s[i]]<mymap[s[i+]])
ans-=mymap[s[i]];
else
ans+=mymap[s[i]];
}
return ans;
}
};

13 Roman to Integer(罗马数字转int Easy)的更多相关文章

  1. 13. Roman to Integer 罗马数字转化为阿拉伯数字(indexOf ()和 toCharArray())easy

    Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol Value I 1 ...

  2. [LeetCode] 13. Roman to Integer 罗马数字转化成整数

    Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol Value I 1 ...

  3. 【LeetCode】13. Roman to Integer 罗马数字转整数

    题目: Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from ...

  4. [leetcode]13. Roman to Integer罗马数字转整数

    Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol Value I 1 ...

  5. LeetCode 13 Roman to Integer(罗马数字转为整数)

    题目链接 https://leetcode.com/problems/roman-to-integer/?tab=Description   int toNumber(char ch) { switc ...

  6. Leetcode#13. Roman to Integer(罗马数字转整数)

    题目描述 罗马数字包含以下七种字符:I, V, X, L,C,D 和 M. 字符 数值 I 1 V 5 X 10 L 50 C 100 D 500 M 1000 例如, 罗马数字 2 写做 II ,即 ...

  7. Leetcode 13. Roman to Integer(水)

    13. Roman to Integer Easy Roman numerals are represented by seven different symbols: I, V, X, L, C, ...

  8. leetCode练题——13. Roman to Integer

    1.题目13. Roman to Integer Roman numerals are represented by seven different symbols: I, V, X, L, C, D ...

  9. C# 写 LeetCode easy #13 Roman to Integer

    13.Roman to Integer Roman numerals are represented by seven different symbols: I, V, X, L, C, D and  ...

随机推荐

  1. 【模拟】NEERC15 J Jump(2015-2016 ACM-ICPC)(Codeforces GYM 100851)

    题目链接: http://codeforces.com/gym/100851 题目大意: 系统里生成一个字符串C,一开始告诉你字符串的长度N(偶数).接着你需要在n+500次内猜出这个字符串是什么. ...

  2. 暴力求解——hdu 1799 循环多少次?

    Description   我们知道,在编程中,我们时常需要考虑到时间复杂度,特别是对于循环的部分.例如, 如果代码中出现 for(i=1;i<=n;i++) OP ; 那么做了n次OP运算,如 ...

  3. 【C#】详解使用Enumerable.Distinct方法去重

    Enumerable.Distinct 方法 是常用的LINQ扩展方法,属于System.Linq的Enumerable方法,可用于去除数组.集合中的重复元素,还可以自定义去重的规则. 有两个重载方法 ...

  4. [转]浏览器如何和Web服务器通信

    http://hi.baidu.com/ywqme/item/b5297014b2e58f4e6826bb74 概述 普通网民打开网页,访问网站,并不需要了解所谓HTTP协议.作为软件工程师,了解一下 ...

  5. hdu 4705 dfs统计更新节点信息

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4705 #pragma comment(linker, "/STACK:16777216&qu ...

  6. RabbitMQ-清空队列中(一个channel或连接中)的Unacknowledged状态的消息

    清空所有:nack 时将参数delivery-tag设为0,multiple设为1. 清空小于等于某delivery-tag的所有消息:nack 时将参数delivery-tag设为正数(介于1和92 ...

  7. WebChat 清爽来袭 -- JavaChat系统Ⅳ

    题记:          WebChat 依然搭配的是 JavaChat 服务器,在不修改原来服务器代码的情况下进行使用终端的扩展.         此次项目的难点在于,Action/Servlet ...

  8. Ubuntu 下 JDK+Tomcat+MySql 环境的搭建

    Linux环境 修改catalina.sh 在“echo "Using CATALINA_BASE: $CATALINA_BASE"”上面加入以下行: JAVA_OPTS=&quo ...

  9. Lucene中string docvalues使用utf-16的优化

    原来的string docvalues使用utf-8编码,载入时转码花费大量时间,我们把转码实现从new String(bytes, "UTF-8")改用lucene的bytesR ...

  10. sync fsync fdatasync ---systemtap跟踪

    aa.stp: probe kernel .function ( "sys_sync" ) { printf ( "probfunc:%s fun:%s\n", ...