LeetCode *** 12. Integer to Roman
2016-04-11 20:14
281 查看
题目:
Given an integer, convert it to a roman numeral.
Input is guaranteed to be within the range from 1 to 3999.
分析:
i am a stupid girl。放张自拍。
代码:
Given an integer, convert it to a roman numeral.
Input is guaranteed to be within the range from 1 to 3999.
分析:
i am a stupid girl。放张自拍。
代码:
class Solution { public: string intToRoman(int num) { string res=""; int p[4]={0}; char symbol[7]={'I','V','X','L','C','D','M'}; for(int i=0;i<4++i){ p[i]=num%10; num/=10; } for(int i=3;i>=0;--i){ int index=i*2; if(p[i]!=0){ int high=p[i]/5; int low=p[i]%5; if(high&&low<4)res+=symbol[index+1]; if(low<4)for(int i=0;i<low;++i)res+=symbol[index]; if(low==4){ res+=symbol[index]; res+=symbol[index+1+high]; } } } return res; } };
相关文章推荐
- AutoreleasePool 分析
- 窗口的布局
- Android Design Support之scroll 初探
- 第六周【项目1-分数类的雏形】
- uboot Makefile 分析
- Java设计模式系列之策略模式
- 决策树模型 ID3/C4.5/CART算法比较
- FAT AP和FIT AP两种组网模式
- String、StringBuffer与StringBuilder之间区别
- Problem F: 在有序数组中插入数据
- 剑指offer:按之字形顺序打印二叉树
- SCOI2016酱油记
- poj 2593&&poj2479(最大两子段和)
- bzoj4521 [Cqoi2016]手机号码
- 当你的网站被疯狂攻击时你能做什么?
- java/android中对回调函数深入灵魂的理解
- Linux C 入门准备
- asp.net 正确的使用session
- java中两个整数相除得到小数点并保留两位小数的方法
- [Java]读取Excel