leetcode 12
来源:互联网 发布:淘宝卖家中心手机版 编辑:程序博客网 时间:2024/04/28 01:57
Given an integer, convert it to a roman numeral.
Input is guaranteed to be within the range from 1 to 3999.
// 1~9: {“I”, “II”, “III”, “IV”, “V”, “VI”, “VII”, “VIII”, “IX”};
// 10~90: {“X”, “XX”, “XXX”, “XL”, “L”, “LX”, “LXX”, “LXXX”, “XC”};
// 100~900: {“C”, “CC”, “CCC”, “CD”, “D”, “DC”, “DCC”, “DCCC”, “CM”};
// 1000~3000: {“M”, “MM”, “MMM”}.
class Solution {public: string intToRoman(int num) { string roman = "IVXLCDM"; string ret; string::const_iterator it = roman.begin(); while (num) { int tmp = num % 10; if (tmp <= 3) ret = string(tmp, *it) + ret; else if (tmp == 4) ret = string(1, *(it)) + *(it + 1) + ret; else if (tmp < 9) ret = string(1, *(it + 1)) + string(tmp - 5, *it) + ret; else ret = string(1, *(it)) + *(it + 2) + ret; num /= 10; it +=2; } return ret; }};
阅读全文
0 0
- Leetcode(12)
- leetcode 12
- LeetCode(12) IntegerToRoman
- leetcode #12 in cpp
- Leetcode日记(12)
- leetcode 576(week 12)
- [Leetcode] 65, 12, 49
- leetcode-个人题解12
- LeetCode刷题(12)
- Leetcode 算法题12
- leetcode
- [leetcode]
- LeetCode
- leetcode
- leetcode
- leetcode:
- leetcode:
- LeetCode
- groovy方法调用
- Interaction triggers in WPF
- 用 Certbot 一键升级你的网站为 Https
- Socket连接池
- 基础前端之JavaScript
- leetcode 12
- Spring注解原理的详细剖析与实现
- rewrite 防止迅雷下载
- Odat渗透攻击oracle资源链接
- 因缺思汀的绕过
- Windows 内核 进程 线程 初探~
- pycharm下的Python console 调试当前程序方法
- C# 关于画图Graphics Bitmap image
- C++中继承关系中的同名隐藏和对策