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;
}

相关文章:

  • 2021-11-22
  • 2021-08-04
  • 2022-03-01
  • 2021-07-13
  • 2021-09-03
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-04
  • 2022-02-16
  • 2021-06-25
  • 2021-07-22
  • 2021-10-15
  • 2021-06-24
相关资源
相似解决方案