-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path12.cpp
More file actions
45 lines (30 loc) · 944 Bytes
/
Copy path12.cpp
File metadata and controls
45 lines (30 loc) · 944 Bytes
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
#include <iostream>
#include <map>
#include <vector>
using namespace std;
class Solution {
public:
string intToRoman(int num) {
vector<pair<int, string>> values = {{1,"I"}, {4,"IV"},{5,"V"},{9,"IX"},{10,"X"},{40,"XL"}, {50,"L"}, {90,"XC"}, {100,"C"},{400,"CD"} , {500,"D"}, {900,"CM"}, {1000,"M"}};
int aux = num;
string value;
int i=values.size()-1, rest = 0;
while(aux > 0){
if(aux >= values[i].first){
// cout <<"valor = " << valor << "values = " << values[i].first << "values2 = " << values[i].second << endl;
value += values[i].second;
// cout << valor << endl;
aux -= values[i].first;
}
else i--;
}
// cout << valor << endl;
return value;
}
};
int main(){
int number;
cin >> number;
Solution sol;
sol.intToRoman(number);
}