描述:

将一个字符串表示的罗马数字转为整数,范围0~3999

解决:

如果后一个比前一个大,则表示减,没什么技巧。

map<char, int> m = {{'I', }, {'V', }, {'X', }, {'L', }, {'C', }, {'M', }, {'D', }};
int romanToInt(string s) {
int ret = ;
int last = ;
for (auto i : s) {
if (m[i] > last) {
ret = ret - last - last + m[i];
last = ;
}
else
ret = ret + m[i];
last = m[i];
}
return ret;
}

leetcode 13 Roman to Integer 罗马数组转整型的更多相关文章

  1. 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 ,即 ...

  2. Leetcode 13. Roman to Integer(水)

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

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

  4. LeetCode - 13. Roman to Integer - 思考if-else与switch的比较 - ( C++ ) - 解题报告

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

  5. Java [leetcode 13] Roman to Integer

    问题描述: Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range fr ...

  6. LeetCode 13. Roman to Integer(c语言版)

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

  7. LeetCode 13 Roman to Integer 解题报告

    题目要求 Roman numerals are represented by seven different symbols: I, V, X, L, C, Dand M. Symbol Value ...

  8. [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 ...

  9. LeetCode——13. Roman to Integer

    一.题目链接:https://leetcode.com/problems/roman-to-integer/ 二.题目大意: 给定一个罗马数字,返回它的整数形式. 三.题解: 这道题与12题恰好相反, ...

随机推荐

  1. L201

    The American public’s obsession with dieting has led to one of the most dangerous healthmisconceptio ...

  2. 设计一个栈,设计一个max()函数,求当前栈中的最大元素

    #include <iostream> using namespace std; #define MAXSIZE 256 typedef struct stack { int top; i ...

  3. 每天一个linux命令(性能、优化):【转载】iostat命令

    Linux系统中的 iostat是I/O statistics(输入/输出统计)的缩写,iostat工具将对系统的磁盘操作活动进行监视.它的特点是汇报磁盘活动统计情况,同时也会汇报出CPU使用情况.同 ...

  4. 51Nod 1049:最大子段和(dp)

    1049 最大子段和  基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题  收藏  关注 N个整数组成的序列a[1],a[2],a[3],-,a[n],求该序列如a[i]+ ...

  5. hibernate流程图

    流程图: 作者: IT程序狮 链接:http://www.imooc.com/article/1296来源:慕课网

  6. .NET可变性解析(协变和逆变)

    [一]何为可变性 可变性是.NET4.0中的一个新特性,可变性可分为 : 协变性.逆变性.不可变性. 那么在.NET4.0之前是否有可变性? 答案是肯定的,我们可以通过下面的几个实例来简单的了解一下. ...

  7. 【转】open-falcon监控windows机器

    open-falcon监控windows机器 时间:2016-05-22 15:34:04   来源:眷恋江南   编辑:涛涛   点击:791   A-A+     最近公司上线了一款新的游戏,用的 ...

  8. qt creator 快捷键 (二)

    多使用快捷键能显著提高工作效率,尽可能减少键盘,鼠标之间切换所浪费的时间.我这里列出个人认为非常重要必须掌握的 Qt Creator 快捷键.看你知道几个? 1 .Ctrl(按住)+ Tab快速切换已 ...

  9. Think in java.chm 第14章 多线程

    例子1引入线程概念通过得到当前线程方式循环主线程做某事 例子2演示了在主线程之外开启多个线程的基本方式 ( new一个extends Thread ) 例子3 ( task extends Threa ...

  10. WinForm各浏览器内核控件

    WebKit.NET webkit-sharp CefSharp awesomium OpenWebKitSharp geckofx MozNet Web Component