/*
* Leetcode12. Integer to Roman
* Funtion: Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.
* Author: LKJ
* Date:2016/7/27
* Hint: Related to12. Roman to Integer
*/
#include <iostream>
#include <vector>
#include <string>
using namespace std;
class Solution {
public:
string intToRoman(int num) {
char* Roman[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"}
};
string result;
result.append(Roman[3][num/1000]);
result.append(Roman[2][num%1000/100]);
result.append(Roman[1][num%100/10]);
result.append(Roman[0][num%10]);
return result;
}
};
int main(){
int myin;
string myout;
Solution SA;
cout << "Please Enter" << endl;
cin >> myin;
myout = SA.intToRoman(myin);
cout << myout << endl;
return 0;
}
LeetCode 简单操作 | 12. Integer to Roman
最新推荐文章于 2024-06-15 09:23:13 发布