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. Python经典资料汇总

    [专题推荐]Python系列英文原版电子书 http://down.51cto.com/zt/104 python简明教程(CHM) http://down.51cto.com/data/49213 ...

  2. hihoCoder挑战赛25

    萌新第一次打hihoCoder的比赛有点慌 T1 T1并不是特别难想到dp就好做了 显而易见的是一个01背包问题 Code: #include <cstdio> #include < ...

  3. PDF 补丁丁 0.5.0.2713 发布(替换字库功能修正字符宽度问题)

    新版本替换字库后,采用新字库的字符宽度.基本上可以满足一般的字库替换需求.请下载新版本测试.

  4. sql数据库表被锁,无法查询

    查看被锁表:   select   request_session_id   spid,OBJECT_NAME(resource_associated_entity_id) tableName    ...

  5. Linux 关机命令

    正确的关机流程是:sync –> shutdown/reboot/halt/poweroff sync 将数据由内存同步到硬盘中. shutdown 关机指令.例如你可以运行如下命令关机: sh ...

  6. php生成图片缩略图,支持png透明

    注:此功能依赖GD2图形库 PHP生成缩略图类   <?php /* * desc: Resize Image(png, jpg, gif) * author: 十年后的卢哥哥(http://w ...

  7. IIC总线解析

    IIC简介: IIC 即Inter-Integrated Circuit(集成电路总线),这种总线类型是由飞利浦半导体公司在八十年代初设计出来的,主要是用来连接整体电路(ICS) ,IIC是一种多向控 ...

  8. SQL基础&笔试题

    仅以此篇博客纪念让我羞愧的一次笔试,作为对数据库基础的恶补. 一.SQL的基本概念: SQL是集数据定义语言DDL,数据操纵语言DML,数据控制语言DCL的功能于一体,可以独立完成数据库生命周期的全部 ...

  9. JSP之->初识JSP

    JSP 引用百度百科的介绍: JSP(Java Server Pages)是由Sun Microsystems公司倡导.许多公司参与一起建立的一种动态网页技术标准.JSP技术有点类似ASP技术,它是在 ...

  10. 各种浏览器的userAgent收集

    window.navigator.userAgent 1) Chrome Win7: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KH ...