整数转罗马数字-LintCode
来源:互联网 发布:软考初级程序员真题 编辑:程序博客网 时间:2024/05/05 08:33
给定一个整数,将其转换成罗马数字。
返回的结果要求在1-3999的范围内。
说明:
什么是 罗马数字?
https://en.wikipedia.org/wiki/Roman_numerals
https://zh.wikipedia.org/wiki/%E7%BD%97%E9%A9%AC%E6%95%B0%E5%AD%97
http://baike.baidu.com/view/42061.htm
样例:
4 -> IV
12 -> XII
21 -> XXI
99 -> XCIX
更多案例,请戳 http://literacy.kent.edu/Minigrants/Cinci/romanchart.htm
#ifndef C418_H#define C418_H#include<iostream>#include<string>#include<vector>using namespace std;class Solution {public: /* * @param n: The integer * @return: Roman representation */ string intToRoman(int n) { // write your code here if (n < 0) return NULL; vector<vector<string>> table{ {"","I","II","III","IV","V","VI","VII","VIII","IX"}, {"","X","XX","XXX","XL","L","LX","LXX","LXXX","XC"}, {"","C","CC","CCC","CD","D","DC","DCC","DCCC","CM"}, {"","M","MM","MMM"} }; string str; str += table[3][n / 1000 % 10]; str += table[2][n / 100 % 10]; str += table[1][n / 10 % 10]; str += table[0][n % 10]; return str; }};#endif
阅读全文
0 0
- LintCode:整数转罗马数字
- Lintcode 罗马数字转整数
- [Lintcode]罗马数字转整数
- lintcode -- 罗马数字转整数
- lintcode -- 整数转罗马数字
- 整数转罗马数字-LintCode
- 罗马数字转整数-LintCode
- lintcode-罗马数字转整数-419
- *[lintcode] Integer to Roman 整数转罗马数字
- lintcode刷题——整数转罗马数字
- lintcode刷题——罗马数字转整数
- [LintCode 419] 罗马数字转整数(Python)
- LintCode笔记(2)——罗马数字转整数
- LintCode笔记(5)——整数转罗马数字
- LeetCode 罗马数字转整数
- 罗马数字转整数
- 整数转罗马数字
- LintCode_419_罗马数字转整数
- java之ObjectOutputStream与ObjectInputStream的使用案例
- 概念——内存空间分段
- python sys和shutill
- CentOS 7 基于yum方式快速搭建LAMP wordpress
- PHP中获取当前页面的完整URL
- 整数转罗马数字-LintCode
- 使用Flask-Mail提供电子邮件支持
- [NOIP2017模拟]分玩具
- 线段树&&树状数组 总结
- WordPress函数:wp_list_categories(分类列表)实例及原理
- Graph Theory NO.5 HDU_1102_Constructing Roads_最小生成树
- 通过node指令自动创建一个package.json文件,并封装发布使用
- 2017.10.11 Problem c 失败总结
- 【python】练习题:去重排序以及列表推导式