leetcode Roman to integer

2015-07-20 17:07:19 ? 作者: ? 浏览: 3

题目:
Given a roman numeral, convert it to an integer.

Input is guaranteed to be within the range from 1 to 3999.

要把罗马数字转换为整数, 罗马数字自行百度

code:

class Solution
{
  public:
    int romanToInt(string s)
    {
       map
   
     Roman; Roman['I'] = 1; Roman['V'] = 5; Roman['X'] =10; Roman['L'] =50; Roman['C'] =100; Roman['D'] =500; Roman['M'] =1000; int i=s.length()-1; int res; while(i>=0) { if(i==s.length()-1) { res=Roman[s[i]]; i--; } if(Roman[s[i]] >= Roman[s[i+1]]) res=res+Roman[s[i]]; else res=res-Roman[s[i]]; i--; } return res; } }; 
   

?

-->

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: