2023每日刷题(六十四)
Leetcode—12.整数转罗马数字
实现代码
const pair<int, string> valueTable[] = {{1000, "M"},{900, "CM"},{500, "D"},{400, "CD"},{100, "C"},{90, "XC"},{50, "L"},{40, "XL"},{10, "X"},{9, "IX"},{5, "V"},{4, "IV"},{1, "I"}};
class Solution {
public:string intToRoman(int num) {string ans;for(auto [digits, valueString]: valueTable) {while(num >= digits) {num -= digits;ans += valueString;}if(num == 0) {return ans;}}return ans;}
};
运行结果
之后我会持续更新,如果喜欢我的文章,请记得一键三连哦,点赞关注收藏,你的每一个赞每一份关注每一次收藏都将是我前进路上的无限动力 !!!↖(▔▽▔)↗感谢支持!