zoukankan      html  css  js  c++  java
  • LeetCode

    12. Integer to Roman 

    Problem's Link

     ----------------------------------------------------------------------------

    Mean: 

    将一个int型的整数转化为罗马数字.

    analyse:

    没什么好说的,直接维基百科.

    Time complexity: O(N)

     

    view code

    /**
    * -----------------------------------------------------------------
    * Copyright (c) 2016 crazyacking.All rights reserved.
    * -----------------------------------------------------------------
    *       Author: crazyacking
    *       Date  : 2016-02-16-11.55
    */
    #include <queue>
    #include <cstdio>
    #include <set>
    #include <string>
    #include <stack>
    #include <cmath>
    #include <climits>
    #include <map>
    #include <cstdlib>
    #include <iostream>
    #include <vector>
    #include <algorithm>
    #include <cstring>
    using namespace std;
    typedef long long(LL);
    typedef unsigned long long(ULL);
    const double eps(1e-8);

    class Solution
    {
    public:
       string intToRoman(int num)
       {
           string M[] = {"", "M", "MM", "MMM"};
           string C[] = {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"};
           string X[] = {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"};
           string I[] = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"};
           return M[num/1000] + C[(num%1000)/100] + X[(num%100)/10] + I[num%10];
       }
    };

    int main()
    {
       Solution solution;
       int n;
       while(cin>>n)
       {
           cout<<solution.intToRoman(n)<<endl;
       }
       return 0;
    }
  • 相关阅读:
    pycharm设置linux中的python解析器进行本地开发
    linux安装python
    Jenkins自动构建的几种方式
    接口加密
    python接口自动化—unittest 常用的断言方法
    cookie 组成结构
    post请求的四种数据格式
    jmeter之数据库相关
    jmeter函数简介
    java_第一年_JDBC(6)
  • 原文地址:https://www.cnblogs.com/crazyacking/p/5035670.html
Copyright © 2011-2022 走看看