-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.cpp
41 lines (38 loc) · 796 Bytes
/
map.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
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <map>
using namespace std;
template <class K, class V>
class Map {
public:
V& operator[](const K& k);
pair<K, V>* begin() {
return &elem[0];
}
pair<K, V>* end() {
return &elem[0] + elem.size();
}
private:
vector<pair<K, V>> elem;
};
template <class K, class V>
V& Map<K, V>::operator[](const K& k) {
for (auto& x : elem) {
if (k == x.first) {
return x.second;
}
}
elem.push_back({k, V{}});
return elem.back().second;
}
int main() {
Map<string, int> map_buf;
for(string s; cin>>s;){
++map_buf[s];
}
for(auto &x:map_buf){
cout << "string: " << x.first << " count: " << x.second << endl;
}
}