直接将各个数位上每个数所代表的罗马数字表示成字符串数组,然后提取出num的各位数,将对应的string相加

class Solution {
public:
string intToRoman(int num) {
string romanSingle[] = {"","I","II","III","IV","V","VI","VII","VIII","IX"};
string romanTen[] = {"","X","XX","XXX","XL","L","LX","LXX","LXXX","XC"};
string romanHundred[] = {"","C","CC","CCC","CD","D","DC","DCC","DCCC","CM"};
string romanThousand[] = {"","M","MM","MMM","MMMM"};
return romanThousand[num/] + romanHundred[(num%)/]
+ romanTen[(num%)/] + romanSingle[num%];
}
};

12. Integer to Roman C++的更多相关文章

  1. Leetcode 12——Integer to Roman

    12.Integer to Roman Given an integer, convert it to a roman numeral. Input is guaranteed to be withi ...

  2. Leetcode 12. Integer to Roman(打表,水)

    12. Integer to Roman Medium Roman numerals are represented by seven different symbols: I, V, X, L, C ...

  3. leetCode练题——12. Integer to Roman

    1.题目 12. Integer to Roman Roman numerals are represented by seven different symbols: I, V, X, L, C,  ...

  4. 《LeetBook》leetcode题解(12):Integer to Roman[M]

    我现在在做一个叫<leetbook>的免费开源书项目,力求提供最易懂的中文思路,目前把解题思路都同步更新到gitbook上了,需要的同学可以去看看 书的地址:https://hk029.g ...

  5. 【LeetCode】12. Integer to Roman (2 solutions)

    Integer to Roman Given an integer, convert it to a roman numeral. Input is guaranteed to be within t ...

  6. [LeetCode] 12. Integer to Roman ☆☆

    Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 t ...

  7. [LeetCode] 12. Integer to Roman 整数转化成罗马数字

    Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol Value I 1 ...

  8. 12. Integer to Roman

    Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 t ...

  9. 【LeetCode】12. Integer to Roman 整型数转罗马数

    题目: Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from ...

  10. 【leetcode】12. Integer to Roman

    题目描述: Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range fr ...

随机推荐

  1. HTML元素 绑定href属性

    给<li>标签绑定href属性 <ul class="honor-list clearfix"> <li style="cursor:poi ...

  2. _itemmod_extra_equipments_enable

    如果这个表是空的 所有装备都可以当成双甲  如果这个表里有配置物品 那么只有表里的 才可以当成双甲 表说明 `comment` 备注 `entry` 物品ID

  3. GYM 101064 2016 USP Try-outs G. The Declaration of Independence 主席树

    G. The Declaration of Independence time limit per test 1 second memory limit per test 256 megabytes ...

  4. Django本地开发,引用静态文件,火狐浏览器不能访问静态文件,谷歌浏览器却能访问静态文件

    查了一下是settings.py设置问题 # Static files (CSS, JavaScript, Images)# https://docs.djangoproject.com/en/1.1 ...

  5. JsonAutoDetect注解找不到错误

    RedisConfig类代码: package com.neo.SpringBoot.config; import java.lang.reflect.Method; import org.sprin ...

  6. 如何在python中调用C语言代码

    1.使用C扩展CPython还为开发者实现了一个有趣的特性,使用Python可以轻松调用C代码 开发者有三种方法可以在自己的Python代码中来调用C编写的函数-ctypes,SWIG,Python/ ...

  7. 《剑指offer》第四十九题(丑数)

    // 面试题49:丑数 // 题目:我们把只包含因子2.3和5的数称作丑数(Ugly Number).求按从小到 // 大的顺序的第1500个丑数.例如6.8都是丑数,但14不是,因为它包含因子7. ...

  8. 学习笔记50—多重假设检验与Bonferroni校正、FDR校正

    总结起来就三句话: (1)当同一个数据集有n次(n>=2)假设检验时,要做多重假设检验校正 (2)对于Bonferroni校正,是将p-value的cutoff除以n做校正,这样差异基因筛选的p ...

  9. Codeforces 797C - Minimal string

    C. Minimal string 题目链接:http://codeforces.com/problemset/problem/797/C time limit per test 1 second m ...

  10. log4j动态监听配置修改

    一般情况下,log4j的配置文件是log4j.properties.但是每次我们修改了配置文件之后程序并不会自动去加载,而需要我们去重启程序.那么怎么样才能让程序不用重启就监听到变化呢.代码如下: p ...