Guest User

Untitled

a guest
Oct 23rd, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <utility>
  4.  
  5. using namespace std;
  6.  
  7. const vector< pair<int, string> > numlist = {{1000,"M"}, {900,"CM"}, {500,"D"}, {400,"CD"}, {100,"C"}, {90,"XC"}, {50,"L"}, {40,"XL"}, {10,"X"}, {9,"IX"}, {5,"V"}, {4,"IV"}, {1,"I"}};
  8.  
  9. string arabToRoman(int n)
  10. {
  11.     string result;
  12.     for( auto i : numlist )
  13.         while(n >= i.first)
  14.         {
  15.             n -= i.first;
  16.             result += i.second;
  17.         }
  18.     return result;
  19. }
  20.  
  21. int main()
  22. {
  23.     for(int i(1); i < 4000; ++i)
  24.         cout << arabToRoman(i) << endl;
  25.     return 0;
  26. }
Add Comment
Please, Sign In to add comment