Skip to content

Commit 7fc846a

Browse files
authored
Create Integer to Roman.cpp
1 parent 8f10cff commit 7fc846a

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Integer to Roman.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
public:
2+
string intToRoman(int num) {
3+
vector<int> values = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
4+
vector<string> symbols = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};
5+
string result = "";
6+
7+
for (int i = 0; i < values.size(); ++i) {
8+
while (num >= values[i]) {
9+
result += symbols[i];
10+
num -= values[i];
11+
}
12+
}
13+
return result;
14+
}
15+
};

0 commit comments

Comments
 (0)