You are viewing a single comment's thread. Return to all comments →
You can use an unordered_multiset (C++11) and its count method to make this easier:
count
#include <iostream> #include <iterator> #include <unordered_set> using namespace std; int main() { int n, q, i; string str; unordered_multiset<string> s; cin >> n; for (i = 0; i < n; ++i) { cin >> str; s.insert(str); } cin >> q; for (i = 0; i < q; ++i) { cin >> str; cout << s.count(str) << '\n'; } }
Seems like cookies are disabled on this browser, please enable them to open this website
Sparse Arrays
You are viewing a single comment's thread. Return to all comments →
You can use an unordered_multiset (C++11) and its
count
method to make this easier: