Integer to Roman -- LeetCode 012
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的更多相关文章
- Integer to Roman - LeetCode
目录 题目链接 注意点 解法 小结 题目链接 Integer to Roman - LeetCode 注意点 考虑输入为0的情况 解法 解法一:从大到小考虑1000,900,500,400,100,9 ...
- Integer To Roman leetcode java
问题描述: Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range fr ...
- 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 ...
- [LeetCode][Python]Integer to Roman
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'https://oj.leetcode.com/problems/integer ...
- 《LeetBook》leetcode题解(12):Integer to Roman[M]
我现在在做一个叫<leetbook>的免费开源书项目,力求提供最易懂的中文思路,目前把解题思路都同步更新到gitbook上了,需要的同学可以去看看 书的地址:https://hk029.g ...
- leetCode练题——12. Integer to Roman
1.题目 12. Integer to Roman Roman numerals are represented by seven different symbols: I, V, X, L, C, ...
- 【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 ...
- 【leetcode】Integer to Roman
Integer to Roman Given an integer, convert it to a roman numeral. Input is guaranteed to be within t ...
- 【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 ...
随机推荐
- ubuntu 14.04 64位安装iNodeClient
ubuntu 14.04 64位安装iNodeClieng(华三校园客服端) http://pan.baidu.com/s/12dpxk ubuntu 14.04 64bit Install H3C ...
- KMP算法解析(转自图灵社区)
KMP算法是一个很精妙的字符串算法,个人认为这个算法十分符合编程美学:十分简洁,而又极难理解.笔者算法学的很烂,所以接触到这个算法的时候也是一头雾水,去网上看各种帖子,发现写着各种KMP算法详解的转载 ...
- c# DataGridView 的一些属性设置,序号,合并头
this.dataGridView1.DataSource = this.dISASTERBindingSource; this.dataGridView1.Locatio ...
- [CentOS] 指定命令别名:Alias & 软链接生成命令 ln -s
参考:CentOS里alias命令详解 每天一个linux命令(35):ln 命令 1. Alias命令 功能描述:我们在进行系统的管理工作一定会有一些我们经常固定使用,但又很长的命令.那我们可以给这 ...
- HTTP_REFERER
.htaccess可以禁止某个来源(referer)的访问,当某个网站对你的网站图片或CSS等文件直接引用的时候,禁止其访问是避免更大损失的关键. RewriteEngine onRewriteCon ...
- 【接口】【USB】1.学习笔记
1.USB的优点: 可以热插拔,即插上后可以自动识别: 系统总线供电,USB共有四根线,一根电源线,一根地线,一根D+线,一根D-线,D+和D-线是差分输入线: 可以支持多种设备,且扩展容易,通过HU ...
- MSDN Library for vs 2010安装及使用(MSDN Library)
VS2010正式版不再有单独的MSDN Library安装选项,VS2010的ISO安装光盘里已经包含有MSDN Library,只不过要手动安装,方法如下: 1.安装完VS2010后,在开始菜单中打 ...
- 根据序列图像聚焦区域获取深度 Shape From Focus
最为超新新新新鸟...我也不知道第一篇文章应该写什么..所以,把自己最近正在研究的东西报一下吧, 研究的东西其实也不算深奥,就是对一个图像序列中的每张图像进行检测,发现每张图片的聚焦清晰区域,找到这个 ...
- React + Redux 入坑指南
Redux 原理 1. 单一数据源 all states ==>Store 随着组件的复杂度上升(包括交互逻辑和业务逻辑),数据来源逐渐混乱,导致组件内部数据调用十分复杂,会产生数据冗余或者混用 ...
- 在Django中进行注册用户的邮件确认
之前利用Flask写博客时(http://hbnnlove.sinaapp.com),我对注册模块的逻辑设计很简单,就是用户填写注册表单,然后提交,数据库会更新User表中的数据,字段主要有用户名,哈 ...