Integer to Roman
来源:互联网 发布:淘宝无理由退货规则 编辑:程序博客网 时间:2024/06/07 02:14
Given an integer, convert it to a roman numeral.
Input is guaranteed to be within the range from 1 to 3999.
题意:
给一个整数,转换成罗马数字
分析:
先将整数和字符数组对应起来。
然后分割整数。
class Solution {public: string intToRoman(int num) { string str; string symbol[]={"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"}; int value[]= {1000,900,500,400, 100, 90, 50, 40, 10, 9, 5, 4, 1}; for(int i=0;num!=0;++i) //value[i]的数值从高到低,循环条件是传入的数num不为0 { while(num>=value[i]) { num-=value[i]; str+=symbol[i];//字符串不断的相加 } } return str; }};
0 0
- Integer to Roman & Roman to Integer
- Integer to Roman & Roman to Integer
- LeetCode Roman to Integer && Integer to Roman
- 【leetcode】Roman to Integer | Integer to Roman
- Leetcode - "Roman to Integer" & "Integer to Roman"
- LeetCode:Roman to Integer,Integer to Roman
- Integer to Roman and Roman to Integer
- LeetCode Integer to Roman & Roman to Integer
- Roman to Integer/Integer to Roman
- leetcode - roman to integer & integer to roman
- "Roman to Integer" and "Integer to Roman"
- Roman to Integer &&Integer to Roman
- Roman to Integer and Integer to Roman
- Roman to Integer/Integer to Roman
- LeetCode:Roman to Integer
- LeetCode: Integer to Roman
- LeetCode: Roman to Integer
- LeetCode Integer to Roman
- Sublime Text 3 在OS X下配置Java编译
- Valid Number
- storm wordcount实例
- 有关 MySQL数据库常见的误解
- HDU 1423
- Integer to Roman
- HDU 1863 畅通工程
- Roman to Integer
- python 字符串组成MySql 命令时,字符串含有单引号或者双引号导致出错解决办法
- 如何使LoadRunner实现加密测试
- nmon下载安装
- Count and Say
- Introduction to Java Programming编程题9.12<变位词>
- Linux内存管理 Slab分配器