问题 C: 查找学生信息
时间限制: 1 Sec 内存限制: 32 MB
提交: 1546 解决: 347
[提交][状态][讨论版][命题人:外部导入]
题目描述
输入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!”
样例输入
5 001 张三 男 19 002 李四 男 20 003 王五 男 18 004 赵六 女 17 005 刘七 女 21 7 003 002 005 004 003 001 006
样例输出
003 王五 男 18 002 李四 男 20 005 刘七 女 21 004 赵六 女 17 003 王五 男 18 001 张三 男 19 No Answer!
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
struct Student{
int xh;
string name, sex, year;
}student[1050];
int main() {
int N;
while (cin >> N) {
int M;
string s;
for (int i = 1; i <= N; i++) {
cin >> student[i].xh >> student[i].name >> student[i].sex >> student[i].year;
}
cin >> M;
while (M--) {
int x = 0;
cin >> s;
for (int i = 0; i < s.length(); i++) {
x *= 10;
x += s[i] - '0';
}
if (x <= N&&x >= 1) {
cout << s << " " << student[x].name << " " << student[x].sex << " " << student[x].year << endl;
}
else cout << "No Answer!" << endl;
}
}
return 0;
}