class Solution {
public:
string intToRoman(int num) {
string result;
int a[] = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
string b[] = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};
int i = 0, cnt;
while(num > 0) {
cnt = num / a[i];
while(cnt--) {
result += b[i];
}
num %= a[i];
i++;
}
return result;
}
};