-
Notifications
You must be signed in to change notification settings - Fork 34
/
Solution.java
82 lines (81 loc) · 1.84 KB
/
Solution.java
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
public class Solution {
public int romanToInt(String s) {
int a;
int b;
int c;
int d;
String sa="";
String sb="";
String sc="";
String sd="";
String flag="ǧ";
for (int i = 0; i < s.length(); i++) {
String t=s.substring(i,i+1);
if (flag.equals("ǧ")) {
if(t.equals("M")){
sa+=t;
continue;
}else {
flag="°Ù";
}
}
if (flag.equals("°Ù")) {
if (t.equals("C")||t.equals("D")||t.equals("M")) {
sb+=t;
continue;
}else {
flag="Ê®";
}
}
if (flag.equals("Ê®")) {
if (t.equals("X")||t.equals("L")||t.equals("C")) {
sc+=t;
continue;
}else {
flag="¸ö";
}
}
if (flag.equals("¸ö")) {
if (t.equals("I")||t.equals("V")||t.equals("X")) {
sd+=t;
continue;
}
}
}
a=sa.length();
if (sb.length()==0) {
b=0;
}else if (sb.contains("M")) {
b=9;
}else if(sb.substring(0,1).equals("D")){
b=5+sb.length()-1;
}else if (sb.contains("D")) {
b=4;
}else {
b=sb.length();
}
if (sc.length()==0) {
c=0;
}else if (sc.contains("C")) {
c=9;
}else if(sc.substring(0,1).equals("L")){
c=5+sc.length()-1;
}else if (sc.contains("L")) {
c=4;
}else {
c=sc.length();
}
if (sd.length()==0) {
d=0;
}else if (sd.contains("X")) {
d=9;
}else if(sd.substring(0,1).equals("V")){
d=5+sd.length()-1;
}else if (sd.contains("V")) {
d=4;
}else {
d=sd.length();
}
return 1000*a+100*b+10*c+d;
}
}