LeetCode:Integer to Roman
来源:互联网 发布:单词记忆方法知乎 编辑:程序博客网 时间:2024/05/24 02:08
Given an integer, convert it to a roman numeral.
Input is guaranteed to be within the range from 1 to 3999.
// Source : https://oj.leetcode.com/problems/integer-to-roman/// Author : Chao Zeng// Date : 2014-12-21struct node { int key; string roman; node(int k, string s):key(k),roman(s){}};class Solution{public: string intToRoman(int num){ vector<node> value; value.push_back(node(1000,"M")); value.push_back(node(900,"CM")); value.push_back(node(500,"D")); value.push_back(node(400,"CD")); value.push_back(node(100,"C")); value.push_back(node(90,"XC")); value.push_back(node(50,"L")); value.push_back(node(40,"XL")); value.push_back(node(10,"X")); value.push_back(node(9,"IX")); value.push_back(node(5,"V")); value.push_back(node(4,"IV")); value.push_back(node(1,"I")); string result; for (int i = 0; i < 13; i++){ while (num >= value[i].key){ num -= value[i].key; result.append(value[i].roman); } } return result; }};
0 0
- LeetCode Roman to Integer && Integer to Roman
- 【leetcode】Roman to Integer | Integer to Roman
- Leetcode - "Roman to Integer" & "Integer to Roman"
- LeetCode:Roman to Integer,Integer to Roman
- LeetCode Integer to Roman & Roman to Integer
- leetcode - roman to integer & integer to roman
- LeetCode:Roman to Integer
- LeetCode: Integer to Roman
- LeetCode: Roman to Integer
- LeetCode Integer to Roman
- LeetCode: Integer to Roman
- LeetCode : Roman to Integer
- [Leetcode] Roman to Integer
- [Leetcode] Integer to Roman
- Leetcode: Integer to Roman
- Leetcode: Roman to Integer
- LeetCode Integer to Roman
- 【leetcode】Roman to Integer
- NENU ACM 14级训练赛 2014-12-21(年度收官战)
- linux创建 / 删除用户及用户管理
- cpu 如何合理地估算线程池大小?
- linux 添加用户、权限
- Linux添加/删除用户和用户组
- LeetCode:Integer to Roman
- 命名规范
- Mysql命令mysqldump:备份数据库
- UVA 621 Secret Research 水题模拟
- Uva 10673-Play with Floor and Ceil(扩展欧几里得)
- java中接口的定义与实现
- jQuery 学习笔记2_万能的jQuery元素选择器
- 分布式与集群的区别
- 设置、获得对话框中 编辑框控件 EDIT 的内容