题目描述
有一学生成绩表,包括学号、姓名、3门课程成绩。请实现如下删除功能:输入一个学生的学号,删除该学生的所有信息。
输入
首先输入一个整数n(1<=n<=100),表示学生人数;
然后输入n行,每行包含一个学生的信息:学号(12位)、姓名(不含空格且不超过20位),以及3个整数,表示3门课成绩,数据之间用空格隔开。
最后一行输入一个学号num。
输出
若要删除的学号不存在,则输出“error!”;否则,输出删除该学生后的所有记录。
样例输入 Copy
3
541207010188 Zhangling 78 95 55
541207010189 Wangli 87 99 88
541207010190 Fangfang 68 76 75
541207010188
样例输出 Copy
541207010189 Wangli 87 99 88
541207010190 Fangfang 68 76 75
代码
#include<stdio.h>
#include<string.h>
struct student{
char xh[13];
char xm[20];
int yw;
int sx;
int yy;
}stu[100];
int main()
{
int n,i=0,k,a,j=0;
char str[13];
//struct student strNull = {NULL,NULL,NULL,NULL,NULL};
scanf("%d",&n);
while(i<n)
{
scanf("%s %s %d %d %d",&stu[i].xh, &stu[i].xm, &stu[i].yw, &stu[i].sx, &stu[i].yy);
i++;
}
scanf("%s",&str);
while(i>=0)
{
if(strcmp(stu[i].xh,str) == 0)
{
a=i;
j=1;
}
i--;
}
if(j==0)
printf("error!");
else
{
for(k=a;k<n;k++)
{
stu[k] = stu[k+1];
}
for(k=0;k<n-1;k++)
printf("%s %s %d %d %d\n",stu[k].xh,stu[k].xm,stu[k].yw,stu[k].sx,stu[k].yy);
}
return 0;
}