#include <bits/stdc++.h>
using namespace std;
void populateRomanChar(unordered_map<int, string>& numberToRomanCharMap) {
numberToRomanCharMap[1000] = "M";
numberToRomanCharMap[900] = "CM";
numberToRomanCharMap[500] = "D";
numberToRomanCharMap[400] = "CD";
numberToRomanCharMap[100] = "C";
numberToRomanCharMap[90] = "XC";
numberToRomanCharMap[50] = "L";
numberToRomanCharMap[40] = "XL";
numberToRomanCharMap[10] = "X";
numberToRomanCharMap[9] = "IX";
numberToRomanCharMap[5] = "V";
numberToRomanCharMap[4] = "IV";
numberToRomanCharMap[1] = "I";
}
string convertToRoman(int number) {
string romanNumber = "";
unordered_map<int, string> numberToRomanCharMap;
populateRomanChar(numberToRomanCharMap);
while(number > 0) {
int tempNum = INT_MIN;
for(auto num: numberToRomanCharMap) {
if(num.first <= number) {
tempNum = max(tempNum, num.first);
}
}
romanNumber += numberToRomanCharMap[tempNum];
number -= tempNum;
}
return romanNumber; // "MCMIV", "XL",
}
int main() {
vector<int> num{2994, 1904, 40, 75};
for(auto x: num) {
cout << "Equivalent Roman Numeral: " << convertToRoman(x) << endl;
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp2b2lkIHBvcHVsYXRlUm9tYW5DaGFyKHVub3JkZXJlZF9tYXA8aW50LCBzdHJpbmc+JiBudW1iZXJUb1JvbWFuQ2hhck1hcCkgewoJbnVtYmVyVG9Sb21hbkNoYXJNYXBbMTAwMF0gPSAiTSI7CgludW1iZXJUb1JvbWFuQ2hhck1hcFs5MDBdID0gIkNNIjsKCW51bWJlclRvUm9tYW5DaGFyTWFwWzUwMF0gPSAiRCI7CgludW1iZXJUb1JvbWFuQ2hhck1hcFs0MDBdID0gIkNEIjsKCW51bWJlclRvUm9tYW5DaGFyTWFwWzEwMF0gPSAiQyI7CgludW1iZXJUb1JvbWFuQ2hhck1hcFs5MF0gPSAiWEMiOwoJbnVtYmVyVG9Sb21hbkNoYXJNYXBbN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