blob: 6f5e9af1a7f30047785de128e24fd63b8b66cc8f (
plain)
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
|
#include <iostream>
#include <vector>
#include <string>
using std::string;
using std::vector;
using std::cin;
struct Query {
string type, name;
int number;
};
vector<Query> read_queries() {
int n;
cin >> n;
vector<Query> queries(n);
for (int i = 0; i < n; ++i) {
cin >> queries[i].type;
if (queries[i].type == "add")
cin >> queries[i].number >> queries[i].name;
else
cin >> queries[i].number;
}
return queries;
}
void write_responses(const vector<string>& result) {
for (size_t i = 0; i < result.size(); ++i)
std::cout << result[i] << "\n";
}
vector<string> process_queries(const vector<Query>& queries) {
vector<string> result;
vector<string> contacts(10000000);
for (size_t i = 0; i < queries.size(); ++i) {
int j = queries[i].number;
if (queries[i].type == "add") {
contacts[j] = queries[i].name;
} else if (queries[i].type == "del") {
contacts[j] = "";
} else {
if (contacts[j].empty())
result.push_back("not found");
else
result.push_back(contacts[j]);
}
}
return result;
}
int main() {
write_responses(process_queries(read_queries()));
return 0;
}
|