LeetCode 12 Integer to Roman
来源:互联网 发布:曼秀雷敦润唇啫喱知乎 编辑:程序博客网 时间:2024/05/29 03:36
题意:
把数字变成罗马数字。
思路:
简单模拟。为了把代码写漂亮点还是可以用用函数什么的。
代码:
//// Created by house on 1/9/17.//class Solution {public: string intToRoman(int num) { stringstream ss; int thousand = num / 1000; while (thousand--) { ss << "M"; } func(ss, num / 100 % 10, "M", "D", "C"); func(ss, num / 10 % 10, "C", "L", "X"); func(ss, num % 10, "X", "V", "I"); return ss.str(); }private: void func(stringstream &ss, int num, string ten, string five, string one) { if (num == 4) { ss << one << five; } else if (num == 9) { ss << one << ten; } else { if (num >= 5) { ss << five; num -= 5; } while (num--) { ss << one; } } }};
0 0
- [LeetCode 12] Integer to Roman
- leetcode 12 Integer to Roman
- [leetcode 12] Integer to Roman
- [Leetcode] 12 - Integer to Roman
- LeetCode | #12 Integer to Roman
- leetcode.12----------Integer to Roman
- leetcode 12 Integer to Roman
- LeetCode 12 - Integer to Roman
- leetcode 12 -- Integer to Roman
- Leetcode #12-Integer to Roman
- LeetCode 12:"Integer to Roman"
- Leetcode#12 Integer to Roman
- leetcode-12Integer to Roman
- leetcode 12: Integer to Roman
- Leetcode 12 Integer to Roman
- Leetcode#12||Integer to Roman
- leetcode 12 Integer to Roman
- LeetCode 12: Integer to Roman
- 【Unity开发】GameObject
- 浅析Qt的事件机制
- PHP快速排序法
- Python3 基础:错误处理
- c++中在类外定义函数
- LeetCode 12 Integer to Roman
- CFX系列(二):CXF处理复杂的对象
- Fetch.Type和FetchMode
- ...........0000000000000000
- Java POI 生成Word文档
- ButterKnife配置
- OpenCV3.0 Examples学习笔记(5)-distrans.cpp
- 北京天宇联科技有限责任公司—T语言html页面开发
- Error:java: Compilation failed: internal java compiler error