本文共 464 字,大约阅读时间需要 1 分钟。
给定一个整数,将其转为罗马数字.
输入保证在 1 到 3999 之间。
放出罗马字母表:
思路很简单,写简洁了不容易。
class Solution {public: string intToRoman(int num) { vectora{ "M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I" }; vector aa{ 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 }; string re; for (int i = 0; i = aa[i]){ num -= aa[i]; re += a[i]; } } return re; }};