题目意思:罗马数字转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. 嵌入式 linux 查看内存

    在Windows系统中查看内存的使用情况很简单,想必大家都已经耳熟能详了,那么在linux系统如何查看内存使用情况呢?下面和大家分享在Linux下查看内存使用情况的free命令: [root@scs- ...

  2. (转载)php 合并数组中的数据,如果键值相等其值相加

    (转载)http://hi.baidu.com/syxrrrr/item/7dfb2387343ce0874414cfdd /* * 合并数据,如果键值相等其值相加 * @param array $d ...

  3. Win7下IE8无法打开https类型的网站解决方法笔记

      现象: 一台笔记本(XP系统),一台台式机(Win7,64位系统),都是IE8,之前没任何问题,访问https也没异常,都能正常访问; 前天突然发现登录火车票网站出现无法打开登录页面情况,后来换其 ...

  4. Codeforces Round #259 (Div. 2) D. Little Pony and Harmony Chest 状压DP

    D. Little Pony and Harmony Chest   Princess Twilight went to Celestia and Luna's old castle to resea ...

  5. 《A First Course in Probability》-chaper6-随机变量的联合分布-独立性

    在探讨联合分布的时候,多个随机变量之间可以是互相独立的.那么利用独立性这个性质我们就能够找到一些那些非独立随机变量没有的求解概率的方法. 对于离散型随机变量的独立联合分布: 离散型随机变量X.Y独立, ...

  6. RHEL 6.4 安装svn和apache

    1.安装软件包(RHEL已经按默认设置安装完成) 需要安装的.rpm软件包: postgresql-libs perl-URI subversion mod_dav_svn 2.创建svn文件夹和版本 ...

  7. Mysql学生管理系统:表的建立,外键一对多,多对多关系,中间关联表的建立

    学生管理系统 管理员注册/登录/注销 注册班级(班级详细信息) 注册学生信息 查看班级信息/查看老师资料 教师注册/注销  查看教师资料  查看学生资料  根据名称/班级/ 查看学生详细信息--支持模 ...

  8. Android Activity启动模式

    <activity android:name=".MainActivity" android:launchMode="singleTask"> &l ...

  9. 实例化讲解 RunLoop

    实例化讲解RunLoop 之前看过很多有关RunLoop的文章,其中要么是主要介绍RunLoop的基本概念,要么是主要讲解RunLoop的底层原理,很少用真正的实例来讲解RunLoop的,这其中有大部 ...

  10. Android常用功能代码块(转)

    1.设置activity无标题,全屏 // 设置为无标题栏 requestWindowFeature(Window.FEATURE_NO_TITLE); // 设置为全屏模式 getWindow(). ...