LeetCode-13-Roman to Integer(number/模拟)-Easy
来源:互联网 发布:iphone设计软件 编辑:程序博客网 时间:2024/06/07 11:45
题意分析:
将罗马数字转换为阿拉伯数字(0-3999);
题目分析:
简单模拟;
解题代码:
class Solution {public: int romanToInt(string s) { map<string, int> m; m.insert(pair<string, int>("0",0)); m.insert(pair<string, int>("I",1)); m.insert(pair<string, int>("V",5)); m.insert(pair<string, int>("X",10)); m.insert(pair<string, int>("L",50)); m.insert(pair<string, int>("C",100)); m.insert(pair<string, int>("D",500)); m.insert(pair<string, int>("M",1000)); int ans=0; int valNext; for(int i=0;i<s.length();i++){ string t=""; t+=s[i]; int val=m.find(t)->second; if(i+1<s.length()){ string n=""; n+=s[i+1]; valNext=m.find(n)->second; if(val<valNext){ ans-=val; }else{ ans+=val; } }else{ ans+=val; } } return ans; }};
0 0
- LeetCode-13-Roman to Integer(number/模拟)-Easy
- [Leetcode 13, Easy] Roman To Integer
- 【LeetCode】(13)Roman to Integer(Easy)
- LeetCode #13 - Roman to Integer - Easy
- Leetcode OJ 13 Roman to Integer [Easy]
- Leetcode[Easy] -- Roman to Integer
- LeetCode 13 Roman to Integer (easy)——python
- LeetCode 13. Roman to Integer -- Easy
- Leetcode 13. Roman to Integer (Easy) (cpp)
- Leetcode: 13. Roman to Integer(Week2, Easy)
- [LeetCode/LinkedIn] Integer to Roman and roman number to Integer
- leetcode integer to roman number conversion
- LeetCode-13-Roman-to-Integer 无聊模拟,递归
- Easy-题目13:13. Roman to Integer
- Easy 13题 Roman to Integer
- Easy 4 Roman to Integer(13)
- leetcode-13:Roman to Integer
- leetcode 13 Roman to Integer
- 欢迎使用CSDN-markdown编辑器
- 获得iphone手机动态ip地址
- 协方差的意义和计算公式
- log4J 日志信息log4j.properties配置说明
- *-servlet.xml解析
- LeetCode-13-Roman to Integer(number/模拟)-Easy
- 抽象类和接口小结
- iOS 学会使用通知(notification)
- EBS Form个性化的工作原理
- Polya定理
- 一道面试题引发的对android中context的研究(一)-SharedPreference是否可以将文件保存在SD卡上
- php项目打包
- 瀑布流
- 怎样成为一个好的技术领导者