-
Notifications
You must be signed in to change notification settings - Fork 0
/
roman-arabic-numerals.cpp
140 lines (136 loc) · 3.21 KB
/
roman-arabic-numerals.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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include <iostream>
using namespace std;
int rom_arab(string p){
int z = 0;
try{
for(int i = 0; i < p.length(); i ++){
if(tolower(p[i]) == 'i'){
try{
if(tolower(p[i+1]) == 'v' || tolower(p[i+1]) == 'x'){
z -= 1;
}
else{
z += 1;
}
}
catch(...){
z += 1;
}
}
else if(tolower(p[i]) == 'v'){
z += 5;
}
else if(tolower(p[i]) == 'x'){
try{
if(tolower(p[i+1]) == 'c' || tolower(p[i+1]) == 'l'){
z -= 10;
}
else{
z += 10;
}
}
catch(...){
z += 10;
}
}
else if(tolower(p[i]) == 'l'){
z += 50;
}
else if(tolower(p[i]) == 'c'){
try{
if(tolower(p[i+1]) == 'm' || tolower(p[i+1]) == 'd'){
z -= 100;
}
else{
z += 100;
}
}
catch(...){
z += 100;
}
}
else if(tolower(p[i]) == 'd'){
z += 500;
}
else if(tolower(p[i]) == 'm'){
z += 1000;
}
else{
cout << "Uncorrect input" << endl;
return 0;
}
}
}
catch(...){
cout << "Uncorrect input" << endl;
return 0;
}
return z;
}
string arab_rom(int s){
string v = "";
try{
while(s > 0){
if(s >= 1000){
s -= 1000;
v += "M";
}
else if(s >= 900){
s -= 900;
v += "CM";
}
else if(s >= 500){
s -= 500;
v += "D";
}
else if(s >= 400){
s -= 400;
v += "CD";
}
else if(s >= 100){
s -= 100;
v += "C";
}
else if(s >= 90){
s -= 90;
v += "XC";
}
else if(s >= 50){
s -= 50;
v += "L";
}
else if(s >= 40){
s -= 40;
v += "XL";
}
else if(s >= 10){
s -= 10;
v += "X";
}
else if(s >= 9){
s -= 9;
v += "IX";
}
else if(s >= 5){
s -= 5;
v += "V";
}
else if(s >= 4){
s -= 4;
v += "IV";
}
else if(s >= 1){
s -= 1;
v += "I";
}
}
}
catch(...){
cout << "Uncorrect input" << endl;
return "";
}
return v;
}
int main(){
return 0;
}