Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <map>
- using namespace std;
- int main()
- {
- map <int, string> roman = {
- { 1, "I" },
- { 2, "II" },
- { 3, "III" },
- { 4, "IV" },
- { 5, "V" },
- { 6, "VI" },
- { 7, "VII" },
- { 8, "VIII" },
- { 9, "IX" },
- { 10, "X" },
- { 20, "XX" },
- { 30, "XXX" },
- { 40, "XL" },
- { 50, "L" },
- { 60, "LX" },
- { 70, "LXX" },
- { 80, "LXXX" },
- { 90, "XC" },
- { 100, "C" },
- { 200, "CC" },
- { 300, "CCC" },
- { 400, "CD" },
- };
- 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 };
- int i = 21;
- int N = 0;
- std::string answer("");
- cout << "Enter an arabian number between 0 and 400: " << endl;
- cin >> N;
- if (cin && N >= 0 && N <= 400)
- {
- while (N > 0)
- {
- N -= arab[i];
- while (N < 0)
- {
- N += arab[i];
- i -= 1;
- N -= arab[i];
- }
- answer += roman[arab[i]];
- i = 21;
- }
- cout << "In roman: " << answer << endl;
- }
- else
- {
- cout << "N should be an integer between 0 and 400!" << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement