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 ...
随机推荐
- XObject.java 对象还没写完,希望电脑不会丢失。坏笑,早点见。
/*面向对象强调的是对象, 面向过程强调的是功能行为,打开行为,关闭行为,执行行为,把多个行为封装成对象执行更强大的功能就是面向对象,是把多个函数, 多 个行为封装在一起,单一的函数执行对象的功能太困 ...
- 深入springMVC源码------文件上传源码解析(下篇)
在上篇<深入springMVC------文件上传源码解析(上篇) >中,介绍了springmvc文件上传相关.那么本篇呢,将进一步介绍springmvc 上传文件的效率问题. 相信大部分 ...
- html/css小练习3
效果图:
- 在input中实现点点点与当鼠标移上去时显示剩余的字
项目中经常会遇到这个问题,在一个内容框中,由于框的宽度是固定的,但是里面的内容却有很多,那么这个时候需求里就要求第一,多余的字要以点点点的形式隐藏,第二,当鼠标移上去的时候要以title提示的方式显示 ...
- Java—泛型
泛型是JDK 5 中引入的一个新特性,泛型提供了编译时类型安全检测机制,该机制允许程序员在编译时检测到非法的类型.泛型本质是参数化类型,也就是所操作的数据类型指定为一个参数. 假定我们有这样一个需求: ...
- java sqlhelper
dbinfo.properties部分: 注意每行末尾不可以有空格 #oracle configure UserName=scott Password=tiger Driver=oracle.jdbc ...
- PDF 补丁丁 0.5.0.2657 发布
新版本修正了导出图片时由于路径存在空白导致出错.在 Windows 10 和高分辨率显示屏上显示字体模糊.控件尺寸错位等各种问题. 默认显示工具栏.
- sql 查询服务器硬盘剩余空间
DECLARE @tb1 Table( drive varchar(20), [MB 可用空间] varchar(20)) INSERT INTO @tb1 Exec master.dbo.xp_fi ...
- pod
在运行 “sudo gem install cocoapods” 的时候出现问题:ERROR: While executing gem ... (Errno::EPERM)Operation not ...
- PHP 捕捉错误,记录到日志
register_shutdown_function("shutdown"); define('ERR_LOG_FILE', '/dev/shm/php_log.txt'); if ...