class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param num int整型 * @param limit int整型 * @return string字符串 */ vector<string> str{"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"}; vector<int> divisor{1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1}; string integerToRomanWithReverse(int num, int limit) { // write code here string ans = ""; int index = 0; while (num) { int quotient = num / divisor[index]; while (quotient--) { ans += str[index]; } num %= divisor[index]; index++; } if (ans.size() >= limit) { reverse(ans.begin(), ans.end()); } return ans; } };