zoukankan      html  css  js  c++  java
  • Roman to Integer

    class Solution {
    public:
        int romanToInt(string s) {
            // Start typing your C/C++ solution below
            // DO NOT write int main() function
            map<char,int> m;
            m['I'] = 1;
            m['V'] = 5;
            m['X'] = 10;
            m['L'] = 50;
            m['D'] = 500;
            m['C'] = 100;
            m['M'] = 1000;
            int pre = 2000;
            int result = 0;
            for(int i = 0;i < s.length();i++)
            {
                if(pre < m[s[i]])
                {
                    result = result + m[s[i]] - pre*2;
                }
                else
                {
                    result = result + m[s[i]];
                }
                pre = m[s[i]];
            }
            return result;
        }
    };

  • 相关阅读:
    shiro之cache问题
    SpringMVC关于请求参数乱码问题
    js递归错误
    说说Javac
    说说CDN
    谈谈HTTP
    谈谈Ajax(二)
    谈谈Ajax(一)
    记一次关于SSM框架的使用错误
    MP实战系列(十四)之分页使用
  • 原文地址:https://www.cnblogs.com/727713-chuan/p/3306110.html
Copyright © 2011-2022 走看看