-
Notifications
You must be signed in to change notification settings - Fork 0
/
decimal to roman
116 lines (116 loc) · 1.86 KB
/
decimal to roman
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import java.util.*;
public class dtr
{
public static void main()
{
Scanner sc=new Scanner(System.in);
String rm="";
rm="";
int dc=sc.nextInt();
int tmp=0;
int chk=0;
if(dc>3999)
{
System.out.println("INVALID INPUT");
chk=-1;
}
else
{
if(dc%1000!=dc)
{
tmp=dc-(dc%1000);
while(tmp!=0)
{
rm=rm+"M";
tmp-=1000;
}
dc=dc%1000;
}
if(dc%500!=dc)
{
if(dc>=900)
{
rm=rm+"CM";
dc=dc%100;
}
else
{
rm=rm+"D";
dc=dc%500;
}
}
if(dc%100!=dc)
{
if(dc>=400)
rm=rm+"CD";
else
{
tmp=dc-(dc%100);
while(tmp!=0)
{
rm=rm+"C";
tmp-=100;
}
}
dc=dc%100;
}
if(dc%50!=dc)
{
if(dc>=90)
{
rm=rm+"XC";
dc=dc%10;
}
else
{
rm=rm+"L";
dc=dc%50;
}
}
if(dc%10!=dc)
{
if(dc>=40)
rm=rm+"XL";
else
{
tmp=dc-(dc%10);
while(tmp!=0)
{
rm=rm+"X";
tmp-=10;
}
}
dc=dc%10;
}
if(dc%5!=dc)
{
if(dc>=9)
{
rm=rm+"IX";
dc=dc%1;
}
else
{
rm=rm+"V";
dc=dc%5;
}
}
if(dc%1!=dc)
{
if(dc>=4)
rm=rm+"IV";
else
{
tmp=dc-(dc%1);
while(tmp!=0)
{
rm=rm+"I";
tmp-=1;
}
}
dc=dc%1;
}
System.out.println(rm);
}
}
}