vakho

2012 - Episode II Problem A

Sep 25th, 2012
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <fstream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     string str;
  9.     int weight(0);
  10.  
  11.     ifstream ifs("roman.in");
  12.     getline(ifs, str);
  13.     ifs.close();
  14.  
  15.     for (int i = 0; i < str.length(); i++)
  16.     {
  17.         switch (str[i])
  18.         {
  19.             case 'I': weight += 1;      break;
  20.             case 'V': weight += 5;      break;
  21.             case 'X': weight += 10;     break;
  22.             case 'L': weight += 50;     break;
  23.             case 'C': weight += 100;    break;
  24.             case 'D': weight += 500;    break;
  25.             case 'M': weight += 1000;   break;
  26.         }
  27.     }
  28.  
  29.     ofstream ofs("roman.out");
  30.     ofs << weight;
  31.     ofs.close();
  32. }
Advertisement
Add Comment
Please, Sign In to add comment