用STL自带的哈希存
#include <iostream>
#include <string>
#include <unordered_map>
using namespace std;
struct Student
{
string name;
string sex;
int age;
};
unordered_map<string, Student> hashTable;
int main()
{
int n, m;
string index;
Student tmp;
cin >> n;
for (int i = 0; i < n; ++i)
{
cin >> index;
cin >> tmp.name >> tmp.sex >> tmp.age;
hashTable[index] = tmp;
}
cin >> m;
for (int i = 0 ; i < m; ++i)
{
cin >> index;
if (hashTable.count(index))
cout << index << " "
<< hashTable[index].name << " "
<< hashTable[index].sex << " "
<< hashTable[index].age << endl;
else
cout << "No Answer!" << endl;
}
return 0;
}