Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <set>
- #include <map>
- #include <cmath>
- #include <iomanip>
- #include <fstream>
- using namespace std;
- typedef long long ll;
- typedef long double ld;
- typedef pair<ll, ll> Pair;
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- map<string, int> better = {{"IV", 4}, {"IX", 9}, {"XL", 40}, {"XC", 90}, {"CD", 400}, {"CM", 900}};
- map<char, ll> cost = {{'I', 1}, {'V', 5}, {'X', 10}, {'L', 50}, {'C', 100}, {'D', 500}, {'M', 1000}};
- string s;
- cin >> s;
- ll ans = 0;
- for(ll i = 0; i < s.size(); i++) {
- if(s[i] == '*') continue;
- if(i+1 < s.size()) {
- string temp = "";
- temp += s[i];
- temp += s[i+1];
- if(better.find(temp) != better.end()) {
- ans += better[temp];
- s[i] = '*';
- s[i+1] = '*';
- continue;
- }
- }
- ans += cost[s[i]];
- }
- cout << ans << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement