forked from illuz/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAC_simulation_1.cpp
50 lines (45 loc) · 911 Bytes
/
AC_simulation_1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
* Author: illuz <iilluzen[at]gmail.com>
* File: AC_simulation_1.cpp
* Create Date: 2014-12-02 23:11:37
* Descripton: simulateion
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 0;
class Solution {
private:
int val[13] = {
1000, 900, 500, 400,
100, 90, 50, 40,
10, 9, 5, 4,
1
};
string syb[13] = {
"M", "CM", "D", "CD",
"C", "XC", "L", "XL",
"X", "IX", "V", "IV",
"I"
};
public:
string intToRoman(int num) {
string roman;
int i = 0, k;
while (num > 0) {
k = num / val[i];
while (k--) {
roman += syb[i];
num -= val[i];
}
i++;
}
return roman;
}
};
int main() {
Solution s;
int n;
while (cin >> n)
cout << s.intToRoman(n) << endl;
return 0;
}