首页 > 其他 > 详细

1760: 学生信息查找

时间:2020-02-09 20:38:03      阅读:55      评论:0      收藏:0      [点我收藏+]

#include<stdio.h>
struct student
{
long no;
char name[9];
int score;
} ;
void input(struct student stu[],int n)
{
int j;
for(j=0;j<n;j++)
{
scanf("%ld %s %d",&stu[j].no,&stu[j].name,&stu[j].score);
}
}
int search(struct student stu[],int n,long xh)
{
int j,flag=1;
for(j=0;j<n;j++)
{
if(stu[j].no==xh)
{
return j;
flag=0;
break;
}
}
if(flag) return -1;
}
void print(struct student stu[],int t)
{
printf("%ld %s %d\n",stu[t].no,stu[t].name,stu[t].score);
}
int main()
{
int i,n,m,t;
long xh;
struct student stu[100];
while(scanf("%d",&n)!=EOF)
{
input(stu,n); //读入n个学生的数据
scanf("%d",&m);
for(i=0;i<m;i++)
{
scanf("%ld",&xh);
t=search(stu,n,xh); //查找学号为xh的学生,不存在返回-1,存在则返回其下标
if(t==-1)
printf("%d not exist\n",xh);
else
print(stu,t); //输出第t个学生的信息
}
}
return 0;
}

1760: 学生信息查找

原文:https://www.cnblogs.com/cy846586184/p/12288463.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!