代码:
#include <cstdio>
#include <fstream>
#include <map>
#include <string>
#include <iostream>
using namespace std;
const int maxn = 1010;
typedef struct Stu{
string id;
string name;
string sex;
int age;
}Stu;
int main(){
// freopen("a.txt", "r", stdin);
int n, m;
string find_id;
map <string, Stu> mp;
Stu s;
while(cin >> n){
for(int i = 0; i < n; ++i){
cin >> s.id >> s.name >> s.sex >> s.age;
mp[s.id] = s;
}
cin >> m;
for(int i = 0; i < m; ++i){
cin >> find_id;
map<string, Stu>::iterator it = mp.find(find_id);
if(it != mp.end()){
cout << mp[find_id].id << " " << mp[find_id].name << " " << mp[find_id].sex << " " << mp[find_id].age << endl;
}
else{
cout << "No Answer!"<<endl;
}
}
}
return 0;
}

本文介绍了一个使用C++实现的学生信息查询系统。系统通过标准输入读取学生的ID、姓名、性别和年龄等信息,并将这些信息存储在一个映射(map)中。随后,程序接受查询请求并输出相应学生的信息。如果未找到指定的学生,则返回特定提示。
687

被折叠的 条评论
为什么被折叠?



