#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
typedef struct
{
char name[21];
int score;
int xh;
int sex;
}stu;
typedef struct
{
stu data[101];
int length;
}sqlist;
void creatslist(sqlist *&L,stu a[],int n)
{
int i=0;
L=(sqlist *)malloc(sizeof(sqlist));
while(i<n)
{
strcpy(L->data[i].name,a[i].name);
L->data[i].score=a[i].score;
L->data[i].xh=a[i].xh;
L->data[i].sex=a[i].sex;
i++;
}
L->length=n;
}
int locatelist(sqlist *L,stu p)
{
int i=0;
while(i<L->length)
{
if(strcmp(L->data[i].name,p.name)==0&&L->data[i].score==p.score)
{
return i+1;
}
i++;
}
return 0;
}
void listdelete(sqlist *L,stu p)
{
int i=0,j;
while(i<L->length)
{
if(strcmp(L->data[i].name,p.name)==0&&L->data[i].score==p.score)
{
for(j=i;j<L->length-1;j++)
{
L->data[j]=L->data[j+1];
}
L->length--;
}
i++;
}
}
void listinsert(sqlist *L,stu p)
{
int n=L->length;
L->data[n]=p;
L->length++;
}
void printlist(sqlist *L)
{
int i=0;
while(i<L->length)
{
printf("%s\n%d %d %d\n",L->data[i].name,L->data[i].score,L->data[i].xh,L->data[i].sex);
i++;
}
}
int main()
{
int n,i;
stu a[100],t;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%s",a[i].name);
scanf("%d%d%d",&a[i].score,&a[i].xh,&a[i].sex);
}
sqlist *L;
L=(sqlist *)malloc(sizeof(sqlist));
L=NULL;
creatslist(L,a,n);
scanf("%s",t.name);
scanf("%d%d%d",&t.score,&t.xh,&t.sex);
if(locatelist(L,t))printf("%d\n",locatelist(L,t));
else printf("error\n");
listdelete(L,t);
listinsert(L,t);
printlist(L);
}
转载请注明原文地址:https://blackberry.8miu.com/read-34557.html