Implement integer to Roman numeral conversion

This commit is contained in:
2026-01-29 01:14:19 +05:30
committed by GitHub
parent 2ee49ea476
commit 42f55f6925
+20
View File
@@ -0,0 +1,20 @@
class Solution {
public:
string intToRoman(int num) {
const vector<pair<int,string>> valueSymbols = {
{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"}
};
string res;
for(auto const &[value,symbol]: valueSymbols){
if(num == 0)
break;
while(num>=value){
res+=symbol;
num-=value;
}
}
return res;
}
};