-
Notifications
You must be signed in to change notification settings - Fork 0
/
13.c
54 lines (52 loc) · 1.16 KB
/
13.c
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
#include <string.h>
int romanToInt(char * s)
{
int j = 0, p = strlen (s);
char c, v;
for (int i = 0; i < p; i ++)
{
switch (s[i])
{
case 'M':
j += 1000;
break;
case 'D':
j += 500;
break;
case 'C':
if (s[i + 1] != 'M' && s[i + 1] != 'D')
{
j += 100;
}else
{
j -= 100;
}
break;
case 'L':
j += 50;
break;
case 'X':
if (s[i + 1] != 'C' && s[i + 1] != 'L')
{
j += 10;
}else
{
j -= 10;
}
break;
case 'V':
j += 5;
break;
case 'I':
if (s[i + 1] != 'X' && s[i + 1] != 'V')
{
j += 1;
}else
{
j -= 1;
}
break;
}
}
return j;
}