只要用unordered_map、map或哈希就可以了。
unordered_map:
#include <iostream>
#include <string>
#include <unordered_map>
using namespace std;
unordered_map<string, int> dict;
int main()
{
int n;
cin >> n;
for (int i = 0; i < n; i++)
{
string name;
cin >> name;
dict.insert({name, 2});
}
int m;
cin >> m;
for (int i = 0; i < m; i++)
{
string name;
cin >> name;
if (dict.find(name) != dict.end())
{
if (dict[name] == 1)
{
cout << "REPEAT\n";
}
else
{
cout << "OK\n";
dict[name]--;
}
}
else
{
cout << "WRONG\n";
}
}
}
很轻松。
map和上面差不多用法一样,就不写了。
Hash就是自己做unordered_map,也是一样的。
建议降 普及-