Advertisement
zhozh_peppa

Untitled

Sep 15th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.32 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <map>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     map <int, string> roman = {
  10.     { 1, "I" },
  11.     { 2, "II" },
  12.     { 3, "III" },
  13.     { 4, "IV" },
  14.     { 5, "V" },
  15.     { 6, "VI" },
  16.     { 7, "VII" },
  17.     { 8, "VIII" },
  18.     { 9, "IX" },
  19.     { 10, "X" },
  20.     { 20, "XX" },
  21.     { 30, "XXX" },
  22.     { 40, "XL" },
  23.     { 50, "L" },
  24.     { 60, "LX" },
  25.     { 70, "LXX" },
  26.     { 80, "LXXX" },
  27.     { 90, "XC" },
  28.     { 100, "C" },
  29.     { 200, "CC" },
  30.     { 300, "CCC" },
  31.     { 400, "CD" },
  32.     };
  33.  
  34.     int arab[22] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 200, 300, 400 };
  35.  
  36.     int i = 21;
  37.     int N = 0;
  38.     std::string answer("");
  39.  
  40.     cout << "Enter an arabian number between 0 and 400: " << endl;
  41.     cin >> N;
  42.  
  43.     if (cin && N >= 0 && N <= 400)
  44.     {
  45.        
  46.         while (N > 0)
  47.         {
  48.             N -= arab[i];
  49.            
  50.             while (N < 0)
  51.             {
  52.                 N += arab[i];
  53.                 i -= 1;
  54.                 N -= arab[i];
  55.             }
  56.            
  57.             answer += roman[arab[i]];
  58.             i = 21;
  59.         }
  60.        
  61.         cout << "In roman: " << answer << endl;
  62.  
  63.     }
  64.     else
  65.     {
  66.         cout << "N should be an integer between 0 and 400!" << endl;
  67.     }
  68.    
  69.    
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement