map的简单使用,没啥好说的 #include <iostream> #include<map> using namespace std; struct student { string cno; string name; string gender; int age; }; map<string, student> mymap; int main() { int n,m; while (cin >> n) { mymap.clear(); // map的初始化 for (int i = 0; i < n; i++) { student temp; cin >> temp.cno >> temp.name >> temp.gender >> temp.age; mymap[temp.cno] = temp; } cin >> m; for (int i = 0; i < m; i++) { string temp; cin >> temp; if (mymap.find(temp) != mymap.end()) { cout << mymap[temp].cno <<' '<< mymap[temp].name<<' '; cout << mymap[temp].gender << ' '<<mymap[temp].age; cout << endl; } else cout << "No Answer!" << endl; } } return 0; }