codeup—查找学生信息

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/m0_37345402/article/details/83185155

题目链接:http://www.codeup.cn/problem.php?cid=100000576&pid=2

题目描述

输入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<cstdio>
#include<cstring>
using namespace std;
int n;
struct Stu{
	char sno[111];
	char sname[111];
	char ssex[11];
	int sage;
}stu[1111];
int main(){
	int x;
	while(cin>>n){
		for(int i=0;i<n;i++){
			cin>>stu[i].sno>>stu[i].sname>>stu[i].ssex>>stu[i].sage;
		}
		cin>>x;
		char id[11111];
		bool f=0;
		for(int i=0;i<x;i++){
			f=0;
			cin>>id;
			for(int j=0;j<n;j++){
				if(strcmp(stu[j].sno,id)==0){
					f=1;
					cout<<id<<" "<<stu[j].sname<<" "<<stu[j].ssex<<" "<<stu[j].sage<<endl;
					break;
				}
			}
			if(!f){
				cout<<"No Answer!"<<endl;
			}
		}
	}
	return 0;
} 

猜你喜欢

转载自blog.csdn.net/m0_37345402/article/details/83185155