daily pastebin goal
23%
SHARE
TWEET

Untitled

a guest Dec 16th, 2018 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <set>
  5. #include <map>
  6. #include <cmath>
  7. #include <iomanip>
  8. #include <fstream>
  9.  
  10.  
  11. using namespace std;
  12.  
  13. typedef long long ll;
  14. typedef long double ld;
  15.  
  16. typedef pair<ll, ll> Pair;
  17.  
  18.  
  19. int main()
  20. {
  21.     ios_base::sync_with_stdio(false);
  22.     cin.tie(0);
  23.     cout.tie(0);
  24.     map<string, int> better = {{"IV", 4}, {"IX", 9}, {"XL", 40}, {"XC", 90}, {"CD", 400}, {"CM", 900}};
  25.     map<char, ll> cost = {{'I', 1}, {'V', 5}, {'X', 10}, {'L', 50}, {'C', 100}, {'D', 500}, {'M', 1000}};
  26.     string s;
  27.     cin >> s;
  28.     ll ans = 0;
  29.     for(ll i = 0; i < s.size(); i++) {
  30.         if(s[i] == '*') continue;
  31.         if(i+1 < s.size()) {
  32.             string temp = "";
  33.             temp += s[i];
  34.             temp += s[i+1];
  35.             if(better.find(temp) != better.end()) {
  36.                 ans += better[temp];
  37.                 s[i] = '*';
  38.                 s[i+1] = '*';
  39.                 continue;
  40.             }
  41.         }
  42.         ans += cost[s[i]];
  43.     }
  44.     cout << ans << endl;
  45.     return 0;
  46.    
  47. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top