-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathccc12s2.cpp
More file actions
45 lines (33 loc) · 717 Bytes
/
ccc12s2.cpp
File metadata and controls
45 lines (33 loc) · 717 Bytes
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
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
map<char, int> base;
base['I'] = 1;
base['V'] = 5;
base['X'] = 10;
base['L'] = 50;
base['C'] = 100;
base['D'] = 500;
base['M'] = 1000;
string s; cin >> s;
int right = s.size()-1;
int prev = 0;
long long ans = 0;
while (right > 0) {
int temp = (s[right-1]-'0') * base[s[right]];
if (base[s[right]] < prev) {
ans -= temp;
}
else {
ans += temp;
}
prev = base[s[right]];
right-=2;
}
cout << ans;
}