13. Roman to Integer C++
直接for循环,并且判断是否出现IV等情况
int which(char ch)
{
if(ch == 'I')
return ;
else if(ch == 'V')
return ;
else if(ch == 'X')
return ;
else if(ch == 'L')
return ;
else if(ch == 'C')
return ;
else if(ch == 'D')
return ;
else return ;
} class Solution {
public:
int romanToInt(string s) {
int flag = ;
int ans = ;
for(int i=; i<s.size(); i++)
{
if(i != s.size()- && which(s.at(i)) < which(s.at(i+)))
{
flag = ;
}
if(flag)
{
ans -= which(s.at(i));
flag = ;
}
else
ans += which(s.at(i));
}
cout << ans;
return ans;
}
};

13. Roman to Integer C++的更多相关文章
- 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 ,即 ...
- Leetcode 13. Roman to Integer(水)
13. Roman to Integer Easy Roman numerals are represented by seven different symbols: I, V, X, L, C, ...
- leetCode练题——13. Roman to Integer
1.题目13. Roman to Integer Roman numerals are represented by seven different symbols: I, V, X, L, C, D ...
- 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 ...
- 13. Roman to Integer【leetcode】
Roman to Integer Given a roman numeral, convert it to an integer. Input is guaranteed to be within t ...
- 【LeetCode】13. Roman to Integer (2 solutions)
Roman to Integer Given a roman numeral, convert it to an integer. Input is guaranteed to be within t ...
- 《LeetBook》leetcode题解(13):Roman to Integer[E]
我现在在做一个叫<leetbook>的免费开源书项目,力求提供最易懂的中文思路,目前把解题思路都同步更新到gitbook上了,需要的同学可以去看看 书的地址:https://hk029.g ...
- 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 ...
- 13. Roman to Integer[E]罗马数字转整数
题目 Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from ...
- [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 ...
随机推荐
- VHDL 乐曲演奏电路设计
前言 无源蜂鸣器在直流信号下不会响,需要方波驱动.输入不同频率的方波会发出不同音调的声音,方波的幅值决定了声音的响度. 目标 乐曲发生电路在节拍(4Hz)的控制下根据乐谱产生合适的分频系数.分频器根据 ...
- Python中的垃圾回收机制
Python的垃圾回收机制 引子: 我们定义变量会申请内存空间来存放变量的值,而内存的容量是有限的,当一个变量值没有用了(简称垃圾)就应该将其占用的内存给回收掉,而变量名是访问到变量值的唯一方式,所以 ...
- toggle 1.9 以后就被删除了
toggle 1.9 以后就被删除了, 1.8.x 以前可用. $(function(){ $(".p_title").toggle( function(){ $(this).n ...
- spring boot 当参数传入开头多个0时,报错:JSON parse error: Invalid numeric value: Leading zeroes not allowed
原因是: Jackson解析json配置的问题 在配置文件中设置下: spring.jackson.parser.allow-numeric-leading-zeros=true
- django Admin文档生成器
Django的admindocs应用可以从模型.视图.模板标签等地方获得文档内容. 一.概览 要激活admindocs,请按下面的步骤操作: 在INSTALLED_APPS内添加django.cont ...
- .NET Core 管道
从用户发请求到服务器响应返回数据 请求从 Request进去 先经过 Middleware(中间件) 然后经过AuthoriationFilters授权验证(token验证和 多租户验证) 在经 ...
- Android requestCode的限制
一. why ? 由于才疏学浅,在开发中requestCode的让我很困惑.困惑是因为什么呢,是因为弄混了.要想弄明白,不困惑,来想一想用到requestCode的地方: ① startActivit ...
- 网络安装OS(配置文件)
●无人值守安装KS文件(redhat用,删除下面中文). #LinuxIParm Config File #Generated by LinuxIParm Configurator #Boot Mod ...
- 关于编码:Unicode/UTF-8/UTF-16/UTF-32
关于编码,绕不开下面这些概念 ①Unicode/UTF-8/UTF-16/UTF-32 ②大小端字节序(big-endian/little-endian) ③BOM(Byte Order Mark) ...
- Codeforces 995 E - Number Clicker
E - Number Clicker 思路:双向搜索 代码: #include<bits/stdc++.h> using namespace std; #define fi first # ...