博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
LeetCode - 12. Integer to Roman
阅读量:6910 次
发布时间:2019-06-27

本文共 1387 字,大约阅读时间需要 4 分钟。

12. Integer to Roman 

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

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

转载于:https://www.cnblogs.com/crazyacking/p/5035670.html

你可能感兴趣的文章
hadoop-003-源码之编译eclipse-plugin
查看>>
即使对象内容都为空,对象本身也是非空的
查看>>
MySQL事务隔离级别详解
查看>>
storm记录--3--Storm的基本概念
查看>>
×××灯marquee标签应用详解
查看>>
彻底弄懂css中单位px和em,rem的区别
查看>>
我的友情链接
查看>>
MapReduce的输出格式
查看>>
AD帐号属性灰色不能修改--解决办法
查看>>
当子页面关闭的时候动态刷新页面的局部
查看>>
javascript 去掉重复的值
查看>>
[置顶] jQuery基础学习(一)
查看>>
SIP Servlet 开篇
查看>>
我在IT中的那些转变
查看>>
用户管理 之 Linux 用户管理工具介绍
查看>>
UIScrollView 滚动视图
查看>>
vc 客户端服务器程序
查看>>
liquibase
查看>>
配置RADIUS客户端
查看>>
Java闭锁_CountDownLatch
查看>>