Leetcode: Integer to Roman
来源:互联网 发布:搜狗输入法mac版 编辑:程序博客网 时间:2024/05/16 09:17
http://oj.leetcode.com/problems/integer-to-roman/
class Solution {public: string intToRoman(int num, int pos){ char *cc="IVXLCDM "; string res; char a=cc[pos*2],b=cc[pos*2+1],c=cc[pos*2+2]; if(num<=3){ for(int i=0;i<num;i++) res.push_back(a); } else if(num==4) { res.push_back(a); res.push_back(b); } else if(num<=8){ res.push_back(b); for(int i=0;i<num-5;i++) res.push_back(a); } else if(num==9){ res.push_back(a); res.push_back(c); } return res; } string intToRoman(int num) { // Note: The Solution object is instantiated only once and is reused by each test case. int len=0; int numTmp=num; while(numTmp!=0) {numTmp/=10;len++;} vector<string> res; for(int i=0;i<len;i++){ res.push_back(intToRoman(num%10,i)); num/=10; } string output; for(int i=res.size()-1;i>=0;i--) output+=res[i]; return output; }};
- 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
- Leetcode: Merge Two Sorted Lists
- Leetcode: Binary Tree Inorder Traversal
- Leetcode: Roman to Integer
- Leetcode: Single Number
- Leetcode: Swap Nodes in Pairs
- Leetcode: Integer to Roman
- Leetcode: Best Time to Buy and Sell Stock
- Leetcode: Balanced Binary Tree
- 嵌入式linux的网络编程(2)--TCP Server程序设计
- note : FAILED宏 和 SUCCEEDED宏 的使用细节
- Leetcode: Search a 2D Matrix
- sublime text 快捷键
- RIP环路避免概述
- pic16f676-i/p再关注到的一款热门PIC MCU