【leetcode】Integer to Roman
Integer to Roman
Given an integer, convert it to a roman numeral.
Input is guaranteed to be within the range from 1 to 3999.
罗马数字的组数规则,有几条须注意掌握;(1)基本数字Ⅰ、X 、C 中的任何一个,自身连用构成数目,或者放在大数的右边连用构成数目,都不能超过三个;放在大数的左边只能用一个。(2)不能把基本数字 V 、L 、D 中的任何一个作为小数放在大数的左边采用相减的方法构成数目;放在大数的右边采用相加的方式构成数目,只能使用一个。(3)V 和 X 左边的小数字只能用Ⅰ。(4)L 和 C 左边的小数字只能用×。(5)D 和 M 左 边的小数字只能用 C
class Solution {
public:
string intToRoman(int num) {
string result="";
string symbol[]={"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"};
int value[]= {,,,, , , , , , , , , };
int i=;
while(num!=)
{
while(num>=value[i])
{
num=num-value[i];
result+=symbol[i];
}
i++;
}
return result;
}
};
【leetcode】Integer to Roman的更多相关文章
- 【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 ...
- 【LeetCode】Integer to Roman(整数转罗马数字)
这道题是LeetCode里的第12道题. 吐了,刚做完"罗马数字转整数",现在又做这个.这个没什么想法,只能想到使用if语句嵌套,或者使用哈希表.但哈希表我还不熟练啊.先拿if嵌套 ...
- 【LeetCode】Integer to English Words 解题报告
Integer to English Words [LeetCode] https://leetcode.com/problems/integer-to-english-words/ Total Ac ...
- 【LeetCode】数学(共106题)
[2]Add Two Numbers (2018年12月23日,review) 链表的高精度加法. 题解:链表专题:https://www.cnblogs.com/zhangwanying/p/979 ...
- 【LeetCode】字符串 string(共112题)
[3]Longest Substring Without Repeating Characters (2019年1月22日,复习) [5]Longest Palindromic Substring ( ...
- 【LeetCode】397. Integer Replacement 解题报告(Python)
[LeetCode]397. Integer Replacement 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/problems/inte ...
- 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java
[LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum dept ...
- 53. Maximum Subarray【leetcode】
53. Maximum Subarray[leetcode] Find the contiguous subarray within an array (containing at least one ...
- 【刷题】【LeetCode】007-整数反转-easy
[刷题][LeetCode]总 用动画的形式呈现解LeetCode题目的思路 参考链接-空 007-整数反转 方法: 弹出和推入数字 & 溢出前进行检查 思路: 我们可以一次构建反转整数的一位 ...
随机推荐
- Centos 7.0查看硬盘使用情况 命令
查看硬盘使用情况 df -hl [root@localhost ~]# df -hl文件系统 容量 已用 可用 已用%. 挂载点/dev/sda3 ...
- Mac常用命令
~ 当前所在目录# 超级用户提示符$ 普通用户提示符 Alfred2 //呼出 option + space rm -rf //删除文件夹pwd //打印当前目录 print working dire ...
- 两种html幻灯片效果
650) this.width=650;" src="http://img1.51cto.com/attachment/201307/165757318.jpg" tit ...
- [Angularjs]asp.net mvc+angularjs+web api单页应用之CRUD操作
写在前面 前篇文章整理了angularjs学习目录,有园子里的朋友问我要这方面的demo,周末也没什么事,就在之前的单页应用的demo上面添加了增删改查的操作.代码比较简单,这里只列举比较重要的代码片 ...
- vmstat、top
vmstat是一个查看虚拟内存(Virtual Memory)使用状况的工具,使用vmstat命令可以得到关于进程.内存.内存分页.堵塞IO.traps及CPU活动的信息. vmstat 最常用的有两 ...
- Gulp实现web服务器
Gulp实现web服务器 阅读目录 一:gulp实现web服务器配置: 二:添加实时刷新(livereload)支持 回到顶部 一:gulp实现web服务器配置: 对于前端开发而言,需要在本地搭建一个 ...
- [百度地图] MultiZMap 修改使用;
MultiZMap修改说明 MultiZMap 是基于百度地图API 封装的一些常用功能类库:主要以prototype方式实现:并且实现了一些辅助的功能,比如添加 Marker 功能,事件管理等: 以 ...
- 终端改变host的类型,还原
- 清北暑假模拟day1 生活
/* 数字三角形,要求第K大的值,可以推知,如果得知k的范围,那么一定是在上一行可转移状态的对应范围内(反证法可以证明),这个在背包九讲里也有提及 */ #include<cstdio> ...
- php——文件下载
php——.doc 文件下载 先看简单实例: 同目录下有两个文件ib.php,test.php与供下载 .doc 文件: test.php文件内容: <?php $attr = glob(&qu ...