题解 | #查找学生信息#
查找学生信息
https://www.nowcoder.com/practice/fe8bff0750c8448081759f3ee0d86bb4
可以直接看成两个字符串,然后利用map的at()返回值与count()看是否存在。
#include <iostream> #include <string> #include <map> using namespace std; map<string,string> mymap; int main() { int n; while (cin >> n) { string num,information; for(int i = 0; i< n;i++){ cin >> num; getline(cin,information); mymap[num] = information; } cin >> n; for(int i = 0;i < n;i++){ cin >> num; if(mymap.count(num) == 0) cout << "No Answer!" << endl; else cout << num << mymap.at(num) << ' ' << endl; } } return 0; }