LeetCode题解(12)--Integer to Roman
https://leetcode.com/problems/integer-to-roman/ 原题: Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999. 思路: 掌握罗马数字规则并实现即可。(具体规则见 LeetCode(13):Roman to Integer) 我的AC代码: 1 class Solution { 2 public: 3 string intToRoman(int num) { 4 string in[] = {"I","V","X","L","C","D","M"}; 5 int t,i=0,j=0; 6 string res="",tmp=""; 7 // cout<<(tmp += in[0]+in[1]); 8 while(num>0){ 9 t=num%10; 10 switch (t){ 11 case 0: break; 12 case 1: tmp = in[i]; break; 13 case 2: tmp = in[i]+in[i]; break; 14 case 3: tmp = in[i]+in[i]+in[i]; break; 15 case 4: tmp = in[i]