SHARE
TWEET

Untitled

a guest Oct 17th, 2019 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4. int getIndex(char rom[7],char c)
  5. {
  6.     for(int i = 0;i<7;i++)
  7.     {
  8.         if(rom[i] == c)
  9.         {
  10.             return i;
  11.         }
  12.     }
  13.     return -1;
  14. }
  15. int main()
  16. {
  17.     char rom[7] = {'I','V','X','L','C','D','M'};
  18.     int dec[7] = {1,5,10,50,100,500,1000};
  19.     char str[255] = {' '};
  20.     int res = 0;
  21.     char c1 = ' ',c2 = ' ';
  22.     int index = 0;
  23.     int a = 0, b = 0;
  24.     while(1)
  25.     {
  26.         c1 = getchar();
  27.         if(c1 == '\n') break;
  28.         c2 = getchar();
  29.         a = dec[getIndex(rom,c1)];
  30.         b = dec[getIndex(rom,c2)];
  31.         if(c2 == '\n') {res += a; break;};
  32.         if(a < b) res += b - a;
  33.         else if(a >= b) res += a + b;
  34.     }
  35.     cout << res;
  36.     return 0;
  37. }
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top