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.
155 lines
2.5 KiB
155 lines
2.5 KiB
#include <stdio.h>
|
|
#include <string.h>>
|
|
int j=0,q=-1;
|
|
char e;
|
|
struct stu
|
|
{
|
|
int id;
|
|
int sclass;
|
|
char name[10];
|
|
float gs;
|
|
float dw;
|
|
float yy;
|
|
}st[100];
|
|
void input()
|
|
{
|
|
printf("id ");
|
|
printf("class ");
|
|
printf("name ");
|
|
printf("score1 ");
|
|
printf("score2 ");
|
|
printf("score3\n");
|
|
scanf("%d %d %s %f %f %f",&st[j].id,&st[j].sclass,&st[j].name,&st[j].gs,&st[j].dw,&st[j].yy);
|
|
printf("continue?\n");
|
|
scanf("%*[^\n]");
|
|
scanf("%*c");
|
|
scanf("%c",&e);
|
|
j++;
|
|
if(e=='n'||e=='N')
|
|
{
|
|
return;
|
|
}
|
|
else if(e=='y'||e=='Y')
|
|
{
|
|
input();
|
|
}
|
|
}
|
|
void cdelete()
|
|
{
|
|
int i,f,m=5,n;
|
|
char mm,s[10];
|
|
printf("Are you sure\n");
|
|
scanf("%*[^\n]");
|
|
scanf("%*c");
|
|
scanf("%c\n",&mm);
|
|
if(mm=='n'||mm=='N')
|
|
{
|
|
output();
|
|
}
|
|
if(mm=='y'||mm=='Y')
|
|
{
|
|
gets(s);
|
|
for(f=0;f<j;f++)
|
|
{
|
|
if(strcmp(s,st[f].name)==0||strcmp(s,st[f].id)==0)
|
|
{
|
|
m=f;
|
|
for(m;m<=j;m++)
|
|
{
|
|
st[m]=st[m+1];
|
|
}
|
|
j--;
|
|
}
|
|
}
|
|
output();
|
|
}
|
|
}
|
|
void select()
|
|
{
|
|
int d,l;
|
|
printf("ÊäÈëѧºÅ»ò°à¼¶");
|
|
scanf("%d",&d);
|
|
for(l=0;l<j;l++)
|
|
{
|
|
if(d==st[l].id||d==st[l].sclass)
|
|
{
|
|
printf("%d %d %s %.1f %.1f %.1f\n",st[l].id,st[l].sclass,st[l].name,st[l].gs,st[l].dw,st[l].yy);
|
|
}
|
|
}
|
|
}
|
|
void inorder()
|
|
{
|
|
int i;
|
|
q++;
|
|
for(i=q+1;i<j;i++)
|
|
{
|
|
if(st[q].sclass>st[i].sclass)
|
|
{
|
|
struct stu temp;
|
|
temp=st[i];
|
|
st[i]=st[q];
|
|
st[q]=temp;
|
|
}
|
|
}
|
|
if(q==j-1)
|
|
{
|
|
q=-1;
|
|
return;
|
|
}
|
|
inorder();
|
|
}
|
|
void corder()
|
|
{
|
|
float a,b;
|
|
int i;
|
|
q++;
|
|
for(i=q+1;i<j;i++)
|
|
{
|
|
a=st[i].dw+st[i].gs+st[i].yy;
|
|
b=st[q].dw+st[q].gs+st[q].yy;
|
|
if(a>b&&st[i].sclass==st[q].sclass)
|
|
{
|
|
struct stu temp;
|
|
temp=st[i];
|
|
st[i]=st[q];
|
|
st[q]=temp;
|
|
}
|
|
}
|
|
if(q==j)
|
|
{
|
|
q=-1;
|
|
return;
|
|
}
|
|
else corder();
|
|
}
|
|
void order()
|
|
{
|
|
inorder();
|
|
corder();
|
|
}
|
|
void output()
|
|
{
|
|
int l=0;
|
|
for(l=0;l<j;l++)
|
|
{
|
|
printf("%d %d %s %.1f %.1f %.1f\n",st[l].id,st[l].sclass,st[l].name,st[l].gs,st[l].dw,st[l].yy);
|
|
}
|
|
}
|
|
int main( )
|
|
{
|
|
int a;
|
|
mn:
|
|
printf("1.Input\n2.Delete\n3.Select\n4.Order\n5.Output\n6.Quit\nplease input your option\n");
|
|
scanf("%d",&a);
|
|
switch(a)
|
|
{
|
|
case 1:input();break;
|
|
case 2:cdelete();break;
|
|
case 3:select();break;
|
|
case 4:order();break;
|
|
case 5:output();break;
|
|
case 6:return 0;
|
|
}
|
|
goto mn;
|
|
}
|