You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

200 lines
3.5 KiB

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define N 100
struct stu_info
{
char num[20];
char cls[20];
char name[20];
float math,physics,english,total; struct stu_info* prev;
struct stu_info* next;
};
struct stu_info stu[N];
int top=0;
struct stu_info *head=NULL;
struct stu_info *tail=NULL;
void print_menu()
{
printf("1.input\n");
printf("2.delete\n");
printf("3.select\n");
printf("4.order\n");
printf("5.output\n");
printf("6.quit\n");
printf("please input your option\n");
}
void print()
{
struct stu_info* p=head;
while (p!=NULL)
{
printf("%s,%s,%s,%.1f,%.1f,%.1f,%.1f\n",p->num,p->cls,p->name,p->math,p->physics,p->english,p->total);
p=p->next;
}
}
void input()
{
char op[20];
struct stu_info* p=NULL;
while(1)
{
p=(struct stu_info *)malloc(sizeof(struct stu_info));
if (head==NULL)
{
head=p;
}
//p->num = (char *)malloc(sizeof(char) * 20);
//p->cls = (char *)malloc(sizeof(char) * 20);
//p->name = (char *)malloc(sizeof(char) * 20);
printf("Id ");
scanf("%s",p->num);
printf("class ");
scanf("%s",p->cls);
printf("name ");
scanf("%s",p->name);
printf("score1 ");
scanf("%f",&p->math);
printf("score2 ");
scanf("%f",&p->physics);
printf("score3 ");
scanf("%f",&p->english);
p->total=p->math+p->physics+p->english;
p->prev=tail;
p->next=NULL;
if(p!=head) tail->next=p;
tail=p;
printf("continue?\n");
do{
scanf("%s",op);
}while(strcmp(op,"yes")!=0&&strcmp(op,"no")!=0);
if(strcmp(op,"no")==0) return;
}
}
void del()
{
struct stu_info* p=head;
char key[20],op[20];
while(1)
{
p=head;
scanf("%s",key);
while(p!=NULL)
{
if(strcmp(p->num,key)==0||strcmp(p->name,key)==0)
{
if(p==head) head=p->next;
else (p->prev)->next=p->next;
(p->next)->prev=p->prev;
}
p=p->next;
}
print();
printf("continue?\n");
do{
scanf("%s",op);
}while(strcmp(op,"yes")!=0&&strcmp(op,"no")!=0);
if(strcmp(op,"no")==0) return;
}
}
void slc()
{
int flag;
struct stu_info* p=head;
char key[20],op[20];
while(1)
{
flag=0;p=head;
scanf("%s",key);
while(p!=NULL)
{
if(strcmp(p->num,key)==0||strcmp(p->cls,key)==0)
{
flag=1;
printf("%s,%s,%s,%.1f,%.1f,%.1f,%.1f\n",p->num,p->cls,p->name,p->math,p->physics,p->english,p->total);
}
p=p->next;
}
if(!flag)
{
printf("there is no eligible student\n");
return;
}
printf("continue?\n");
do{
scanf("%s",op);
}while(strcmp(op,"yes")!=0&&strcmp(op,"no")!=0);
if(strcmp(op,"no")==0) return;
}
}
void order()
{
struct stu_info* p=tail;
struct stu_info* q=head;
struct stu_info* tmp=NULL;
while(p!=NULL)
{
q=head;
while(q!=p)
{
if(strcmp((q)->cls,(q->next)->cls)==1||strcmp((q)->cls,(q->next)->cls)==0&&((q)->total<(q->next)->total))
{
if(p==q->next) p=q;
if(head==q) head=q->next;
else (q->prev)->next=q->next;
if(tail==q->next) tail=q;
else ((q->next)->next)->prev=q;
tmp=q->next;
q->next=tmp->next;
tmp->prev=q->prev;
tmp->next=q;
q->prev=tmp;
}
else q=q->next;
}
p=p->prev;
}
print();
return;
}
int main()
{
int op;
while(1)
{
print_menu();
scanf("%d",&op);
switch(op)
{
case(1):
input();
break;
case(2):
del();
break;
case(3):
slc();
break;
case(4):
order();
break;
case(5):
print();
break;
case(6):
return 0;
}
}
}