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;
    }
  • 相关阅读:
    android dumpsys meminfo 详解
    效率思维模式与Zombie Scrum
    Mac中Run快捷键修改
    airtest+pytest实战教程05—登录智学网app
    对select函数的理解
    Appium定位元素
    Hack The Box——ServMon
    Oracle DG常用视图与运维护常用操作
    Oracle EBS订单的流程(Order->AR)
    财经法规与会计职业道德
  • 原文地址:https://www.cnblogs.com/crazyacking/p/5035670.html
Copyright © 2011-2022 走看看