-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
76 lines (73 loc) · 1.37 KB
/
Copy pathmain.cpp
File metadata and controls
76 lines (73 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//
// main.cpp
// leetcode012
//
// Created by 萧天牧 on 17/2/23.
// Copyright © 2017年 萧天牧. All rights reserved.
//
#include <iostream>
using namespace std;
string intToRoman(int num) {
string roma = "MDCLXVI";
int roma_num[] = {1000, 500, 100, 50, 10, 5, 1};
string res;
for(int i = 0; i < num / 1000; i++)
res += "M";
num %= 1000;
if(num / 100 == 9){
res += "CM";
num -= 900;
}
else if (num >= 500)
{
res += "D";
num -= 500;
}
if (num / 100 == 4){
res += "CD";
num -= 400;
}
else
for (int i = 0; i < num / 100; i++)
res += "C";
num %= 100;
if(num / 10 == 9){
res += "XC";
num -= 90;
}
else if (num >= 50)
{
res += "L";
num -= 50;
}
if (num / 10 == 4){
res += "XL";
num -= 40;
}
else
for (int i = 0; i < num / 10; i++)
res += "X";
num %= 10;
if (num == 9){
res += "IX";
return res;
}
else if(num >= 5){
res += "V";
num -= 5;
}
if (num / 1 == 4){
res += "IV";
}
else{
for (int i = 0; i < num ; i++)
res += "I";
}
return res;
}
int main(int argc, const char * argv[]) {
int a;
while (cin >> a) {
cout << intToRoman(a) << endl;
}
}