We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 2eb3e24 commit 6ec7bbcCopy full SHA for 6ec7bbc
1 file changed
romantointeger
@@ -0,0 +1,36 @@
1
+def romantointeger(A):
2
+ result=0
3
+ i=0
4
+ while(i<len(A)):
5
+ curr=value(A[i])
6
+ if(i+1<len(A)):
7
+ next=value(A[i+1])
8
+ if(curr>=next):
9
+ result=result+curr
10
+ i=i+1
11
+ else:
12
+ result=result+(next-curr)
13
+ i=i+2
14
15
16
17
+ return result
18
+
19
20
21
+def value(A):
22
+ if(A=='I'):
23
+ return 1
24
+ if(A=='V'):
25
+ return 5
26
+ if(A=='X'):
27
+ return 10
28
+ if(A=='L'):
29
+ return 50
30
+ if(A=='C'):
31
+ return 100
32
+ if(A=='D'):
33
+ return 500
34
+ if(A=='M'):
35
+ return 1000
36
0 commit comments