1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
class Solution {
public:
string intToRoman(int num) {
string output="";
int value[13] = {1000,900,500,400,100,90,50,40,10,9,5,4,1};
string valueS[13] = {"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"};
int count=num;
int pos=0;
while (count!=0)
{
if (count>=value[pos])
{
count=count-value[pos];
output=output+valueS[pos];
}
else
pos++;
}
return output;
}
};
|