- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.cpp
More file actions
Latest commit
17 lines (17 loc) · 497 Bytes
/
Copy pathSolution.cpp
File metadata and controls
17 lines (17 loc) · 497 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
classSolution {
public:
string intToRoman(int num) {
vector<string> roman = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};
vector<int> values = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
string res = "";
int i = 0;
while (num > 0 ) {
while(num >= values[i]) {
num -= values[i];
res.append(roman[i]);
}
i++;
}
return res;
}
};