-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
39 lines (36 loc) · 1.08 KB
/
main.cpp
File metadata and controls
39 lines (36 loc) · 1.08 KB
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
#include "hash_map.h"
//#include "test_map.h"
#include <iostream>
#include <cstdlib>
#include <stdexcept>
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
HashMap<int, int> map;
using HashMapIterator = HashMap<int, int>::iterator;
int n;
std::cin >> n;
for (int i = 0; i < n; ++i) {
char code;
int key;
std::cin >> code;
if (code != '!' && code != '<')
std::cin >> key;
if (code == '-')
map.erase(key);
else if (code == '?') {
auto it = map.find(key);
std::cout << (it == map.end() ? -1 : it->second) << "\n";
} else if (code == '+') {
int val;
std::cin >> val;
map[key] = val;
} else if (code == '<') {
for(HashMapIterator it = map.begin(); it != map.end(); ++it)
std::cout << it->first << " " << it->second << "\n";
} else if (code == '!')
map.clear();
}
std::cout << map.size() << "\n";
return 0;
}