1. 程式人生 > >Integer to Roman 整數轉換成羅馬數字

Integer to Roman 整數轉換成羅馬數字

class Solution {
public:
    string intToRoman(int num) {
    string str="";
int value[]={1000,900,500,400,100,90,50,40,10,9,5,4,1};
string symbol[]={"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"};
for(int i=0;i<13&&num>0;i++)
{
while(num>=value[i])
{
num-=value[i];
str+=symbol[i];
}
}

return str;
    }
};