12. Integer to Roman
- Total Accepted: 97165
- Total Submissions: 223436
- Difficulty: Medium
- Contributors: Admin
Given an integer, convert it to a roman numeral.
Input is guaranteed to be within the range from 1 to 3999.
Subscribe to see which companies asked this question.
Show Similar Problems
12. Integer to Roman
- Total Accepted: 97165
- Total Submissions: 223436
- Difficulty: Medium
- Contributors: Admin
Given an integer, convert it to a roman numeral.
Input is guaranteed to be within the range from 1 to 3999.
Subscribe to see which companies asked this question.
Show Similar Problems
Description
Submissions
Solutions
#include<iostream>
#include<string>
using namespace std;
string b[4][10]={
{"","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","","","","","",""}
};
class Solution {
public:
string intToRoman(int num) {
int a[4];
for(int i=0;i<4;i++){
a[i]=num%10;
num/=10;
}
string out="";
for(int i=0;i<4;i++){
out+=b[3-i][a[3-i]];
}
return out;
}
};
#include<iostream>
#include<string>
using namespace std;
string b[4][10]={
{"","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","","","","","",""}
};
class Solution {
public:
string intToRoman(int num) {
int a[4];
for(int i=0;i<4;i++){
a[i]=num%10;
num/=10;
}
string out="";
for(int i=0;i<4;i++){
out+=b[3-i][a[3-i]];
}
return out;
}
};
- Total Accepted: 97165
- Total Submissions: 223436
- Difficulty: Medium
- Contributors: Admin
Given an integer, convert it to a roman numeral.
Input is guaranteed to be within the range from 1 to 3999.
Subscribe to see which companies asked this question.
Show Similar Problems