码迷,mamicode.com
首页 > 其他好文 > 详细

1761: 学生信息删除

时间:2020-02-09 20:27:01      阅读:81      评论:0      收藏:0      [点我收藏+]

标签:ret   成功   return   eof   NPU   name   信息   void   input   

#include<stdio.h>
struct student
{
long no;
char name[9];
int score;
};
void input(struct student stu[100],int n)
{
int i;
for(i=0;i<n;i++)
{
scanf("%ld %s %d",&stu[i].no,&stu[i].name,&stu[i].score);
}
return;
}
int delet(struct student stu[],int n,long xh)
{
int i, flag=1,j;
for(i=0;i<n;i++)
{
if(stu[i].no==xh)
{
for(j=i;j<n;j++)
{
stu[j]=stu[j+1];
}
return 1;
flag=0;
}
}if(flag) return -1;

}
void print(struct student stu[],int n)
{
int i;
for(i=0;i<n;i++)
{
printf("%ld %s %d\n",stu[i].no,stu[i].name,stu[i].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=delet(stu,n,xh); //删除学号为xh的学生,删除不成功返回-1,删除成功则返回1
if(t==-1)
printf("delete Failed\n",xh);
else
{
n--;
printf("delete Success\n");
}
}
print(stu,n); //输出n个学生的信息
}
return 0;
}

1761: 学生信息删除

标签:ret   成功   return   eof   NPU   name   信息   void   input   

原文地址:https://www.cnblogs.com/cy846586184/p/12288471.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!