题目意思:罗马数字转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. 一键安装mysql5.6

    #!/bin/bash # @Name:install_mysql.sh # @Author:Eivllom # @Create -- # @Modify -- app_soft="/app ...

  2. Selenium自动化测试环境搭建汇总(一):Selenium+Eclipse+Junit+TestNG

    第一步 安装JDK JDk1.7. 下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-188026 ...

  3. 数据结构——HDU1312:Red and Black(DFS)

    题目描述 There is a rectangular room, covered with square tiles. Each tile is colored either red or blac ...

  4. 《Euclidea3》-Eta-07

    Q: 分析:考虑到充分利用三等分和角度的信息,这里我们只需做出一个36°的角即可. 考虑一个顶角是36°的等腰三角形.如下图. 设AD=a1,CD=a2,根据相似,易得a1:a2=(√5-1)/2. ...

  5. [转载]Web前端和后端之区分,以及面临的挑战

    原文地址:Web前端和后端之区分,以及面临的挑战[转]作者:joyostyle 在我们实际的开发过程中,我们当前这样定位前端.后端开发人员. 1)前端开发人员:精通JS,能熟练应用JQuery,懂CS ...

  6. curl 模拟ajax 请求

    主要是在header请求里加一个  X-Requested-With: XMLHttpRequest curl -v -H "X-Requested-With: XMLHttpRequest ...

  7. mysql @变量和变量的区别及怎么判断记录唯一性

    DELIMITER// drop PROCEDURE if EXISTS test.express; create PROCEDURE test.express() BEGIN ) into @a f ...

  8. [转] 剖析 epoll ET/LT 触发方式的性能差异误解(定性分析)

    http://blog.chinaunix.net/uid-17299695-id-3059078.html PS:Select和Poll都是水平触发,epoll默认也是水平触发 ET模式仅当状态发生 ...

  9. frontpage 正则 查找与替换

    frontpage正则查找替换 frontpage查找用{}[不是() ]来匹配pattern, 并获取这一匹配 替换时匹配的字符用\1 \2 \3表示 第 N 个标记表达式 \N 在“替换”表达式中 ...

  10. IIS相关问题

    问题:使用vs开发项目完成后,发布在本地IIS上,访问链接出现如下情况: 解决方案:打开IIS--->>