Problem:

Given an integer, convert it to a roman numeral.

Input is guaranteed to be within the range from 1 to 3999.

Convert Arabic numerals to Roman numerals for output . Baidu corresponding I V X L C D M, representative 1,5,10,50,100,500,1000 And then write a sub function , Enter the number and the corresponding digit level , If the position is level 1, Qianwei 4. Because it won't be more than 4000 at most . So it can be as follows . Pay attention ,string The usage is very good , Just add it directly .

```class Solution {
private:
string corRoman(int val, int level)
{
string base, media, large;
string s = "";
if (level == ) // bits
{
base = "I";
media = "V";
large = "X";
}
else if (level == )
{
base = "X";
media = "L";
large = "C";
}
else if (level == )
{
base = "C";
media = "D";
large = "M";
}
else
{
base = "M";
}
if (val == )
return "";
if( val < )
{
for ( int i = ; i < val; i++)
s += base;
return s;
}
if (val == )
{
return base + media;
}
if (val < )
{
s = media;
for (int i = ; i < val; i++)
s+=base;
return s;
}
return base + large;
}
public:
string intToRoman(int num)
{
string s;
int a;
for (int i = ; i > ; i-- )
{
a = num/pow(,i - );
num %= (int)pow(, i - );
s+=corRoman(a,i);
}
return s;
}
};```

So you Accept 了 .

## leetcode The first 12 topic --Integer to Roman More articles about

1. 【LeetCode】12 &amp; 13 - Integer to Roman &amp; Roman to Integer

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

2. LeetCode（12）Integer to Roman

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

3. LeetCodeOJ Brush the topic 12【Integer to Roman】

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

4. LeetCode The first [13] topic (Java)：Roman to Integer

subject : Roman numeral conversion questions :easy Topic content :Roman numerals are represented by seven different symbols: I, V, X, L, C, D ...

5. leetcode Solutions to problems ||Integer to Roman problem

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

6. LeetCode：12. Roman to Integer （Easy）

1. Original link https://leetcode.com/problems/roman-to-integer/description/ 2. Subject requirements (1) Convert Roman numerals to integers :(2) Range 1-399 ...

7. [LeetCode] 12. Integer to Roman Convert integers to Roman numerals

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

8. [LeetCode] Integer to Roman Convert integers to Roman numerals

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

9. [LeetCode][Python]Integer to Roman

# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'https://oj.leetcode.com/problems/integer ...

## Random recommendation

1. centos7 install lnmp Environmental Science

preparation One . Configure firewall vim /etc/sysconfig/iptables Turn on 80 port .3306.22 port -A INPUT -m state --state NEW -m tcp -p tc ...

2. Shell Learning notes - Environment variable configuration file ( turn )

One .source command function : At present bash Environment to read and execute the commands in the configuration file 1. Command format source The configuration file   or   . The configuration file 2. Order sample [root@localhost ~]# sou ...

3. java web Plug in development

1. Support pagelet2. Menu extension 3. Static file access 4. development environment . 5.OSGi platform . tms:pagelet It's a jsp label <div> <tms:pagelet show=&q ...

4. Pressure dp-poj-1170-Shopping Offers

Topic link : http://poj.org/problem?id=1170 The title mean : There is... In the shopping cart b Kind of (0=<b<=5) goods , Each item tells the item code c(1=<c<=999), The number of ...

5. JQUERY Special characters

// Replace special characters \$(this).val(\$(this).val().replace(/[~'!<>@#\$%^&*()-+_=:]/g, ""));

6. utilize eclipse Create a new one maven Project steps ：

1. open eclipse, Left click in the upper left corner File, Choose New, Left click to select Maven Project, The following screen appears : 2. Take out the tick , Choose your own workspace for your project , Here's the picture , I built it in my workspace worksp ...

7. IOS modify UIImage size

stay iOS in ,uiimage There are no properties to modify the size , To change in the code uiimage Size of picture , Need to expand UIImage class , as follows : The header file : #import<UIKit/UIKit.h> @int ...

8. Annotation type Schedule Configure scheduled tasks

@Component public class ScheduledTasks { @Autowired private ActivityService activityService; // 1000 ...

9. Feign Performance optimization considerations

One .FeignClient annotation FeignClient The annotation is @Target(ElementType.TYPE) modification , Express FeignClient The purpose of annotation is on the interface @FeignClient(name ...

10. JavaScript Summary of common functions

1.test() Method var str = "wzltestreg"; var reg = new RegExp("wzl", ""); al ...