=900){res+="CM";num-=900;}else if(num>=500){res+="D";num-=500;}else if。【12】Integer|【12】Integer to Roman。" />

【12】Integer|【12】Integer to Roman

【【12】Integer|【12】Integer to Roman】按9 5 4 1一点一点减

string intToRoman(int num) { string res=""; int c=num/1000; res+=string(c,'M'); num-=(c*1000); if(num>=900){res+="CM"; num-=900; } else if(num>=500){res+="D"; num-=500; } else if(num>=400){res+="CD"; num-=400; } c=num/100; res+=string(c,'C'); num-=(c*100); if(num>=90){res+="XC"; num-=90; } else if(num>=50){res+="L"; num-=50; } else if(num>=40){res+="XL"; num-=40; } c=num/10; res+=string(c,'X'); num-=(c*10); if(num>=9){res+="IX"; num-=9; } else if(num>=5){res+="V"; num-=5; } else if(num>=4){res+="IV"; num-=4; } c=num; res+=string(c,'I'); return res; }



    推荐阅读