【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-整数反转 方法: 弹出和推入数字 & 溢出前进行检查 思路: 我们可以一次构建反转整数的一位 ...
随机推荐
- Java中关于HashMap的元素遍历的顺序问题
Java中关于HashMap的元素遍历的顺序问题 今天在使用如下的方式遍历HashMap里面的元素时 1 for (Entry<String, String> entry : hashMa ...
- javascript生成二维码
参考: http://www.w3dev.cn/article/20140617/javascript-create-QR-code.aspx
- CentOS7挂载分区教程
http://www.centoscn.com/CentOS/config/2014/1016/3955.html
- jQuery EasyUI API 中文文档 - ComboGrid 组合表格
jQuery EasyUI API 中文文档 - ComboGrid 组合表格,需要的朋友可以参考下. 扩展自 $.fn.combo.defaults 和 $.fn.datagrid.defaults ...
- 卸载金山猎豹免费WIfi后,上不了网的解决办法
进入网络和共享中心,打开网络适配器,右键无线连接,属性,就在打开属性的那个页面,在靠上的位置有个LieBao xxx Driver,卸载. 然后,打开浏览器,试试这个链接:www.baidu.com. ...
- asp.net mvc ClaimsIdentity 授权研究 (还是测试版 有bug)
安装 Microsoft.Owin.Host.SystemWeb Identity.Core Microsoft.Owin.Security.Cookies 在是startup.cs做如下修改 p ...
- MFC CStatic类动态创建
如果我使用下面风格: m_PictureCtrl.Create(NULL, WS_EX_TRANSPARENT|WS_CHILD|WS_VISIBLE|WS_TABSTOP|SS_OWNERDRAW, ...
- C#委托全解析
什么是委托? 委托类似于C语 ...
- 懒加载的用处和赋nil操作[iOS开发教程]
懒加载的用处和赋nil操作 1:数据,清空操作: self.array = nil; 2:归档从新从本地获取数据 self.archive = nil; ##id = nil的用处 block当参数, ...
- 通过url地址传递base64加密参数遇到的问题整理
1. base64的加密解密方法在C#的类库中就有 QueryString中的加号变成了空格问题 Server.UrlEncode(username),获取到的编码又将等于号变成了%3d; 到底改怎么 ...