题目描述
输入N个学生的信息,然后进行查询。
输入描述:
输入的第一行为N,即学生的个数(N<=1000)
接下来的N行包括N个学生的信息,信息格式如下:
01 李江 男 21
02 刘唐 男 23
03 张军 男 19
04 王娜 女 19
然后输入一个M(M<=10000),接下来会有M行,代表M次查询,每行输入一个学号,格式如下:
02
03
01
04
输出描述:
输出M行,每行包括一个对应于查询的学生的信息。
如果没有对应的学生信息,则输出“No Answer!”
#include <iostream>
#include <string>
using namespace std;
struct student{
int id;
string name;
string gender;
int age;
};
int main(){
student stu[1000];
int n;
int m;
cin >> n;
for(int i = 0; i < n; i++)
cin >> stu[i].id >> stu[i].name >> stu[i].gender >> stu[i].age;
cin >> m;
for(int i = 0; i < m; i++){
int ID;
cin >> ID;
int j;
for(j = 0; j < n; j++){
if(stu[j].id == ID){
cout << stu[j].id << " "
<< stu[j].name << " "
<< stu[j].gender << " "
<< stu[j].age << endl;
break;
}
}
if(j == n) cout << "No Answer!" << endl;
}
return 0;
}