-
Notifications
You must be signed in to change notification settings - Fork 0
/
leetcode.cpp
59 lines (57 loc) · 1.31 KB
/
leetcode.cpp
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
#include<iostream>
using namespace std;
string intToRoman(int num){
string ans;
int len,x=num,d,i=0,m=0;
while(x){
x = x/10;
len++;
}
for(int j=0;i<len-1;j++){
int add;
if(d/10==0){
if(d%5==0){
switch(m){
case 0:
ans.at(i)="V";
case 1:
ans.at(i)="L";
case 2:
ans.at(i)="D";
}
}
else if(d==4){
switch(m){
case 0:
ans.at(i)="IV";
case 1:
ans.at(i)="XL";
case 2:
ans.at(i)="CD";
}
}
else{
switch(m){
case 0:
ans.at(i)="I";
case 1:
ans.at(i)="X";
case 2:
ans.at(i)="C";
case 3:
ans.at(i)="M";
}
}
i++;
m=0;
}
d = d/10;
m++;
}
return ans;
}
int main(){
int num;
cin >> num;
cout << intToRoman(num);
}