博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
12. 整数转罗马数字
阅读量:4029 次
发布时间:2019-05-24

本文共 464 字,大约阅读时间需要 1 分钟。

给定一个整数,将其转为罗马数字.

输入保证在 1 到 3999 之间。

放出罗马字母表:

思路很简单,写简洁了不容易。

class Solution {public:    string intToRoman(int num) {        vector
a{ "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; }};

 

你可能感兴趣的文章
[LeetCode By Python]118. Pascal's Triangle
查看>>
[LeetCode By Python]121. Best Time to Buy and Sell Stock
查看>>
[LeetCode By Python]122. Best Time to Buy and Sell Stock II
查看>>
[LeetCode By Python]125. Valid Palindrome
查看>>
[LeetCode By Python]136. Single Number
查看>>
[LeetCode By Python]167. Two Sum II - Input array is sorted
查看>>
[LeetCode BY Python]169. Majority Element
查看>>
[LeetCode By Python]172. Factorial Trailing Zeroes
查看>>
[LeetCode By MYSQL] Combine Two Tables
查看>>
python jieba分词模块的基本用法
查看>>
[CCF BY C++]2017.12 最小差值
查看>>
[CCF BY C++]2017-12 游戏
查看>>
如何打开ipynb文件
查看>>
[Leetcode BY python ]190. Reverse Bits
查看>>
面试---刷牛客算法题
查看>>
Android下调用收发短信邮件等(转载)
查看>>
Android中电池信息(Battery information)的取得
查看>>
SVN客户端命令详解
查看>>
Android/Linux 内存监视
查看>>
Linux系统信息查看
查看>>