Given an integer, convert it to a roman numeral.

Input is guaranteed to be within the range from 1 to 3999.

Solution 1:

class Solution
{
public:
string intToRoman(int num)
{
     // 关键
const int radix[] = {, , , , , ,
, , , , , , };
const string symbol[] = {"M", "CM", "D", "CD", "C", "XC",
"L", "XL", "X", "IX", "V", "IV", "I"}; string roman;
for(size_t i = ; num > ; ++i)
{
int count = num / radix[i];
num %= radix[i];
for(; count > ; --count) roman += symbol[i];
}
return roman;
}
};

Integer to Roman -- LeetCode 012的更多相关文章

  1. Integer to Roman - LeetCode

    目录 题目链接 注意点 解法 小结 题目链接 Integer to Roman - LeetCode 注意点 考虑输入为0的情况 解法 解法一:从大到小考虑1000,900,500,400,100,9 ...

  2. Integer To Roman leetcode java

    问题描述: Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range fr ...

  3. integer to roman leetcode c++实现

    Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 t ...

  4. [LeetCode][Python]Integer to Roman

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'https://oj.leetcode.com/problems/integer ...

  5. 《LeetBook》leetcode题解(12):Integer to Roman[M]

    我现在在做一个叫<leetbook>的免费开源书项目,力求提供最易懂的中文思路,目前把解题思路都同步更新到gitbook上了,需要的同学可以去看看 书的地址:https://hk029.g ...

  6. leetCode练题——12. Integer to Roman

    1.题目 12. Integer to Roman Roman numerals are represented by seven different symbols: I, V, X, L, C,  ...

  7. 【LeetCode】Roman to Integer & Integer to Roman

    Roman to Integer Given a roman numeral, convert it to an integer. Input is guaranteed to be within t ...

  8. 【leetcode】Integer to Roman

    Integer to Roman Given an integer, convert it to a roman numeral. Input is guaranteed to be within t ...

  9. 【leetcode】Integer to Roman & Roman to Integer(easy)

    Roman to Integer Given a roman numeral, convert it to an integer. Input is guaranteed to be within t ...

随机推荐

  1. android 使用httpclient访问网络

    在主活动类中,调用一个线程访问网络(android4.0以上耗时的操作不能放在主线程中):       //声明两个Button对象,与一个TextView对象private TextView mTe ...

  2. redis命令全集(自用)

    1.连接操作相关的命令 quit:关闭连接(connection) auth:简单密码认证 2.对value操作的命令 exists(key):确认一个key是否存在 del(key):删除一个key ...

  3. 键盘对应的ASCII码

    ESC键 VK_ESCAPE (27)回车键: VK_RETURN (13)TAB键: VK_TAB (9)Caps Lock键: VK_CAPITAL (20)Shift键: VK_SHIFT ($ ...

  4. 【软件工具】Driver Booster3永久激活法

    原作者網址:erik2041999 (YouTube) 1.安装Driver Booster3 (档案已附) 2.使用此启动码0187E-B9764-4D9FA-211B3断网启动 3.保持断网状态并 ...

  5. Dependency Scope

    Dependency Scope <dependency>中还引入了<scope>,它主要管理依赖的部署.目前<scope>可以使用5个值: * compile,缺 ...

  6. 一眼看懂KMP匹配算法

    KMP算法——快速从字符串M(母串)中找出与字符串Z(子串)匹配的子串 例1: 0 1 2 3 4 5 M:a b c a b d Z:  a b d BF算法(最一般的算法,也叫“蛮力算法”): 将 ...

  7. OC中用NSSortDescriptor对象进行数组排序

    //创建一个数组 NSArray *array = @[@"one", @"two", @"three", @"four" ...

  8. Crowd 2.7汉化中文包(原创首发)

    介绍:Crowd是用来集成Atlassian各类产品用户集成系统,如Jira,Confluence等的集中用户管理平台.可对组.成员关系.用户.目录.应用程序及权限进行综合管理,并可实现其他程序的单点 ...

  9. While循环

    package ForType; public class ForType { /** * @param args */ public static void main(String[] args) ...

  10. AWS-CDH5.5安装-软件下载

    1.下载安装介质 下载CM安装文件: [root@ip---- cm5.5.0]# wget -c -r -nd -np -k -L -A rpm http://archive-primary.clo ...