Leetcode84: Integer to Roman
来源:互联网 发布:手机上编程软件 编辑:程序博客网 时间:2024/06/05 13:32
Given an integer, convert it to a roman numeral.
Input is guaranteed to be within the range from 1 to 3999.
struct node{ int key; string szRoman; node(int k, string s):key(k), szRoman(s){} }; string intToRoman(int num){ vector<node> dct; dct.push_back(node(1000, "M")); dct.push_back(node(900, "CM")); dct.push_back(node(500, "D")); dct.push_back(node(400, "CD")); dct.push_back(node(100, "C")); dct.push_back(node(90, "XC")); dct.push_back(node(50, "L")); dct.push_back(node(40, "XL")); dct.push_back(node(10, "X")); dct.push_back(node(9,"IX")); dct.push_back(node(5,"V")); dct.push_back(node(4,"IV")); dct.push_back(node(1,"I")); string res; int i = 0; while(num > 0) { if(num/dct[i].key == 0) { i += 1; continue; } for(int j = 0; j < num/dct[i].key; ++j) res.append(dct[i].szRoman); num%=dct[i].key; } return res; }
0 0
- Leetcode84: Integer to Roman
- Integer to Roman & Roman to Integer
- Integer to Roman & Roman to Integer
- 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
- Integer to Roman and Roman to Integer
- LeetCode Integer to Roman & Roman to Integer
- Roman to Integer/Integer to Roman
- leetcode - roman to integer & integer to roman
- "Roman to Integer" and "Integer to Roman"
- Roman to Integer &&Integer to Roman
- Roman to Integer and Integer to Roman
- Roman to Integer/Integer to Roman
- LeetCode:Roman to Integer
- LeetCode: Integer to Roman
- LeetCode: Roman to Integer
- PAT(甲级)1079
- eclipse scala工程
- jquery中eq()与get()的区别
- (负载均衡)nginx+keepalive
- 工具类JdbcUtils
- Leetcode84: Integer to Roman
- jquery中prop()方法和attr()方法的区别浅析
- PAT(甲级)1080
- Java中的StringTokenizer类的使用方法
- 【bzoj2438】 [中山市选2011]杀人游戏 强连通分量
- 3.访问修饰符
- 自学ios开发之项目第一天~(微博项目)
- UML项目完成总结
- ViewPager显示不完整的解决办法