-
Notifications
You must be signed in to change notification settings - Fork 0
/
test3.cpp
67 lines (65 loc) · 1.4 KB
/
test3.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
#include <bits/stdc++.h>
using namespace std;
struct comp
{
bool operator()(const string &s1, const string &s2) const
{
if (s1.length() != s2.length())
return s1.length() < s2.length();
for (int i = 0; i < s1.length();i++)
{
if (s1[i] != s2[i])
return s1[i] < s2[i];
}
return false;
}
};
int
main()
{
map<string, int, comp> num;
vector<string> D;
int n;
int total = 0;
cin >> n;
while (n--)
{
string str;
cin >> str;
if (str == "insert")
{
string s;
cin >> s;
D.push_back(s);
if (num.count(s))
num[s]++;
else
num[s] = 1;
total++;
}
else if (str == "min" && total != 0)
{
cout << (*num.begin()).first << endl;
}
else if (str == "max" && total != 0)
{
cout << (*num.rbegin()).first << endl;
}
else if (str == "find")
{
int tmp;
cin >> tmp;
if (tmp < total)
cout << D[tmp - 1] << endl;
}
else if (str == "amount")
{
string tmp;
cin >> tmp;
if (num.count(tmp))
cout << num[tmp] << endl;
else
cout << "0\n";
}
}
}