-
Notifications
You must be signed in to change notification settings - Fork 0
/
IntToRoman.cpp
35 lines (31 loc) · 1013 Bytes
/
IntToRoman.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
#include<string>
using namespace std;
string intToRoman(int num) {
if(num==0)
return "";
if(num==9)
return "IX";
if(num==4)
return "IV";
if(num >= 40 && num < 50)
return "XL" + intToRoman(num-40);
if(num >= 90 && num < 100)
return "XC" + intToRoman(num-90);
if(num >= 400 && num < 500)
return "CD" + intToRoman(num-400);
if(num >= 900 && num < 1000)
return "CM" + intToRoman(num-900);
if(num<=3)
return "I"+intToRoman(num-1);
if(num<10)
return "V"+intToRoman(num-5);
if(num<40)
return "X"+intToRoman(num-10);
if(num<100)
return "L"+intToRoman(num-50);
if(num<400)
return "C"+intToRoman(num-100);
if(num<1000)
return "D"+intToRoman(num-500);
return "M"+intToRoman(num-1000);
}