Q:Given a roman numeral, convert it to an integer.
Input is guaranteed to be within the range from 1 to 3999.
该题是要将罗马数字转换成integer。罗马数字的定义可见维基百科:Roman numerals .
罗马数字是基于下面7个符号:
罗马数字的1...
分类:
其他好文 时间:
2015-02-03 11:09:32
阅读次数:
152
这个题目是把罗马数字转换为整数,比如输入字符串 MCMLXXXIV,输出为整数1984。观测罗马数字的规律,我们得到,其实可以直接相加每个字符代表的整数即可,比如CLIII这个罗马数字对应的整数即为100+50+1+1+1=153。但是,若是两个字符代表一个数字时,我们就需要注意了,比如IV即为5-1=4。因此,我们得到规律,没读入字符串的一个字符,都将它与之后一个字符代表的数字比较,如果前者较小...
分类:
其他好文 时间:
2015-01-28 09:57:36
阅读次数:
194
Given a roman numeral, convert it to an integer.
Input is guaranteed to be within the range from 1 to 3999.
题意:讲罗马数字转换成阿拉伯数字
思路:了解罗马数字的构造后,从后往前处理就行了
class Solution {
public:
int romanToInt(s...
分类:
其他好文 时间:
2015-01-23 00:54:13
阅读次数:
207
Given a roman numeral, convert it to an integer.
Input is guaranteed to be within the range from 1 to 3999.
题目的意思是将给定的罗马数字转换为一个整数
什么是罗马数字:
I, II, III, IV, V, VI, VII, VIII, IX, X....
分类:
其他好文 时间:
2015-01-15 20:19:12
阅读次数:
205
这个题目很简单,只是不了解数字与罗马数字转换关系的话就无从下手了。
题目:
原理与思路:
罗马数字有如下符号:
基本字符
I
V
X
L
C
D
M
对应阿拉伯数字
1
5
10
50
100
500
1000
计数规则:
相同的数字连写,所表示的数等于这些数字相加得到的数...
分类:
其他好文 时间:
2014-12-20 10:30:21
阅读次数:
244
Given a roman numeral, convert it to an integer.
Input is guaranteed to be within the range from 1 to 3999.
class Solution {
public:
int romanToInt(string s) {
int weight[26];
...
分类:
其他好文 时间:
2014-12-19 14:30:53
阅读次数:
160
Given an integer, convert it to a roman numeral.
Input is guaranteed to be within the range from 1 to 3999.
class Solution {
public:
string intToRoman(int num) {
char symbol[] = {'I', ...
分类:
其他好文 时间:
2014-12-18 12:03:50
阅读次数:
162
将罗马数字转换成整型数字。前面已经介绍过罗马数字了这里就不赘述了。...
分类:
其他好文 时间:
2014-11-30 00:49:06
阅读次数:
143
Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.Solution:此题是要求把罗马数字转换成数字。首先,学习一下罗马数字,参考罗马数字罗...
分类:
其他好文 时间:
2014-10-19 13:01:54
阅读次数:
248
写在前面:
这两道题合起来写吧,其实整数转罗马数字我前天就写完了,当我想写罗马数转整数的时候竟然脑子一片空白,想了几分钟就想起来Map,本着学习的目的最终还是不想用Map,坚持C语言,今天脑子里直接涌出了Switch方式转换,看来“蹲在马桶上编程”的方式还是蛮不错的o(^▽^)o
整数转罗马数字:主要建立对应关系,输出时有点像百钱百鸡
罗马数字转整数:输入罗马数字(其实就是字符数组)后,fo...
分类:
其他好文 时间:
2014-09-29 01:29:37
阅读次数:
403