题解 | #查找学生信息#
查找学生信息
https://www.nowcoder.com/practice/fe8bff0750c8448081759f3ee0d86bb4
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;
}
阿里云工作强度 585人发布
