-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRomanNumerals.cpp
82 lines (71 loc) · 1.56 KB
/
RomanNumerals.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include<iostream>
#include<limits>
#include<string>
#include<map>
#include<unordered_map>
using namespace std;
// long long int uni(string s)
// {
// // int cnt=0;
// // for(int i=0;i<10;i++)
// // {
// // string j=to_string(i);
// // // bool found = bool(s.find(j));
// // if (s.find(j) != std::string::npos)
// // {
// // cnt++;
// // }
// // }
// // return cnt;
// // create a map to store the
// // frequency of characters
// unordered_map<char, int> m;
// // traverse the string
// for (int i = 0; i < s.length(); i++) {
// // increase the frequency of character
// m[s[i]]++;
// }
// return m.size();
// }
long long int uni(long long int num)
{
string str = to_string(num);
unordered_map<char, int> m;
for (int i = 0; i < str.length(); i++) {
m[str[i]]++;
}
return m.size();
}
void roman(int number)
{
int num[] = {1,4,5,9,10,40,50,90,100,400,500,900,1000};
string sym[] = {"I","IV","V","IX","X","XL","L","XC","C","CD","D","CM","M"};
int i=12;
while(number>0)
{
int div= number/num[i];
number=number%num[i];
while(div--)
{
cout<<sym[i];
}
i--;
}
cout<<endl;
}
int main()
{
int n;
cin>>n;
for(int i=0;i<n;i++)
{
long long int number,dist;
cin>>number;
// string str=to_string(number);
// dist=uni(str);
dist=uni(number);
roman(dist);
cout<<dist<<endl;
}
return 0;
}