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.

326 lines
7.9 KiB

#include <stdio.h>
#include <string.h>
#pragma warning (disable:4996)
typedef struct Student
{
char id[20];
char clas[20];
char name[20];
double score1;
double score2;
double score3;
double score;
}Student;
Student stu[50]={{"10001","11","Zhang",99.5,88.5,89.5,277.5},{"10002","12","Yang",77.9,56.5,87.5,221.9},{"10003","11","Liang",92.5,99.0,60.5,252.0}};
void start()
{
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD>\n");
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<6F><6E>\n");
}//<2F><>ʼ<EFBFBD><CABC>ʾ<EFBFBD><CABE><EFBFBD>˵<EFBFBD><CBB5>ĺ<EFBFBD><C4BA><EFBFBD>
void input()
{ int i;int flag=1;
int len=lens(stu);
scanf("%s %s %s %lf %lf %lf", stu[len].id,stu[len].clas,&stu[len].name,&stu[len].score1, &stu[len].score2, &stu[len].score3);
char nul3=getchar();
stu[len].score = stu[len].score1 + stu[len].score2 + stu[len].score3;
for(i=0;i<len;i++)
{
if(strcmp(stu[len].id,stu[i].id)==0)
{
flag=0;
stu[i]=stu[len];
}
}
if(flag==1)
{
for( i=0;i<len;i++)
{
printf("%s %s %s %.2f %.2f %.2f %.2f\n",stu[i].id,stu[i].clas,stu[i].name,stu[i].score1,stu[i].score2,stu[i].score3,stu[i].score);
}
}
if(flag==0)
{
for( i=0;i<len;i++)
{
if((strcmp(stu[len].id,stu[i].id)==0))
printf("%s %s %s %.2f %.2f %.2f %.2f\n",stu[i].id,stu[i].clas,stu[i].name,stu[i].score1,stu[i].score2,stu[i].score3,stu[i].score);
else if((strcmp(stu[len].id,stu[i].id)!=0))
printf("%s %s %s %.2f %.2f %.2f %.2f\n",stu[i].id,stu[i].clas,stu[i].name,stu[i].score1,stu[i].score2,stu[i].score3,stu[i].score);
}
stu[len].id[0] ='0';
stu[len].id[1] ='0';
stu[len].id[2] ='0';
stu[len].id[3] ='0';
stu[len].id[4] ='0';
stu[len].score1=0;
stu[len].score2=0;
stu[len].score3=0;
stu[len].score = 0;
}
} //<2F><><EFBFBD>µĿռ<C4BF><D5BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߿<EFBFBD><DFBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>id<69><64>ͬʱ<CDAC><CAB1>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸<EFBFBD>
void output()
{
int len=lens(stu);
double temp;
int i,j;
for (i = 0; i < 2; i++)
{
for (j = 0; j < 2 - i; j++)
{
if (stu[j].score > stu[j + 1].score)
{
Student temp = stu[j];
stu[j] = stu[j + 1];
stu[j + 1] = temp;
}
}
}
for( i=0;i<len;i++)
{
printf("%s %s %s %.2f %.2f %.2f %.2f\n",stu[i].id,stu[i].clas,stu[i].name,stu[i].score1,stu[i].score2,stu[i].score3,stu[i].score);
}
} //<2F><><EFBFBD>ִܷ<DCB7>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int lens(Student stu[])
{
int i;
int court = 0;
for (i = 0;i < 50;i++)
{
if (stu[i].score3 > 0)
{
court++;
}
if(stu[i].score3 <= 0)
{
break;
}
}
return court;
} //<2F><>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void order()
{
int i,j,k;
int a[100] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
int c[100] = { 0 };
int number = 0;
int len = lens(stu);
for (i = 0;i < len;i++)
{
stu[i].score = stu[i].score1 + stu[i].score2 + stu[i].score3;
}
stu[len + 1].score = 0;
for (i = 0;i < len;i++)
{
for (j = 0;j < len - i-1;j++)
{
if (strcmp(stu[j].clas, stu[j + 1].clas) > 0)
{
stu[len + 1] = stu[j];
stu[j] = stu[j + 1];
stu[j + 1] =stu[len + 1];
}
}
}
stu[len].score = 6458;
for (i = 0;i < len;i++)
{
if (stu[i].score == stu[i + 1].score)
{
a[number]++;
}
if (stu[i].score != stu[i + 1].score)
{
a[number]++;
c[number + 1] = i + 1;
number++;
}
}
for (k = 0;k < number;k++)
{
for (i = 0;i < a[k];i++)
{
for (j = c[k];j < a[k] - i;j++)
{
if (stu[j].score < stu[j + 1].score)
{
stu[len + 1] = stu[j];
stu[j] = stu[j + 1];
stu[j + 1] = stu[len + 1];
}
}
}
}
for (i = 0;i < len;i++)
{
printf("%s %s %.2f %.2f %.2f %.2f\n", stu[i].id, stu[i].clas, stu[i].score1, stu[i].score2, stu[i].score3, stu[i].score);
}
} //<2F>Ȱ<EFBFBD><C8B0><EFBFBD>ٰ<EFBFBD><D9B0>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD><EFBFBD>
void delete()
{
int len = lens(stu);int flag = 0;
int i,j,k;
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫɾ<EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD>Ż<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
char a[10];//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD>Ż<EFBFBD><C5BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
scanf("%s", a);
char nul2=getchar();
for (i = 0;i < len;i++)
{
if (strcmp(a, stu[i].id) == 0 || strcmp(a, stu[i].name) == 0)
{
flag = 1;//<2F>еĻ<D0B5>ɾ<EFBFBD><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
for (k = i + 1;k < len;k++)
{
stu[k - 1] = stu[k];//<2F><EFBFBD><E0B5B1>ɾ<EFBFBD><C9BE>
}
}
}
if (flag == 0)//û<>еĻ<D0B5><C4BB><EFBFBD><EFBFBD><EFBFBD>ԭ<EFBFBD><D4AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
for (j = 0;j < len;j++)
{
printf("%s %s %s %.2f %.2f %.2f %.2f\n", stu[j].id,stu[j].clas, stu[j].name, stu[j].score1, stu[j].score2, stu[j].score3, stu[j].score);
}
}
if (flag == 1)//<2F>еĻ<D0B5><C4BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֮<EFBFBD><D6AE><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD>ɾ<EFBFBD><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>
{
len = lens(stu) - 1;
for (j = 0;j < len;j++)
{
printf("%s %s %s %.2f %.2f %.2f %.2f\n", stu[j].id,stu[j].clas, stu[j].name, stu[j].score1, stu[j].score2, stu[j].score3, stu[j].score);
}
}
} //ɾ<><C9BE>
void select(char* a,char* b,int i,double k)
{
int len = lens(stu),j;
if (i == 1)
{
for (j = 0;j < len;j++)
{
if (strcmp(stu[j].clas,a)>=0 && strcmp(stu[j].clas,b)<=0)
{
printf("%s %s %s %.2f %.2f %.2f %.2f\n", stu[j].id, stu[j].clas, stu[j].name, stu[j].score1, stu[j].score2, stu[j].score3, stu[j].score);
}
}
}
else if (i == 2)
{
for (j = 0;j < len;j++)
{
if (strcmp(stu[j].id,a)>=0 && strcmp(stu[j].id,b)<=0)
{
printf("%s %s %s %.2f %.2f %.2f %.2f\n", stu[j].id, stu[j].clas, stu[j].name, stu[j].score1, stu[j].score2, stu[j].score3, stu[j].score);
}
}
}
else if (i == 3)
{
for (j = 0;j < len;j++)
{
if(strcmp(stu[j].name,a)>=0 && strcmp(stu[j].name,b)<=0)
{
printf("%s %s %s %.2f %.2f %.2f %.2f\n", stu[j].id, stu[j].clas, stu[j].name, stu[j].score1, stu[j].score2, stu[j].score3, stu[j].score);
}
}
}
else if (i == 4)
{
for (j = 0;j < len;j++)
{
if (stu[j].score>=k)
{
printf("%s %s %s %.2f %.2f %.2f %.2f\n", stu[j].id, stu[j].clas, stu[j].name, stu[j].score1, stu[j].score2, stu[j].score3, stu[j].score);
}
}
}
} //a<><61>ʾ<EFBFBD><CABE>ʼ<EFBFBD><CABC>b<EFBFBD><62>ʾĩβ
int main()
{
while(1)
{
start();
char g = getchar();
char nul=getchar();
if (g == '1')
{
printf("Please input info of a student<6E><74><EFBFBD><EFBFBD>ʽΪid clas name score1 score2 score3<65><33>:\n");
input();
}
else if(g=='4')
{
order();
}
else if(g=='5')
{
output();
}
else if(g=='2')
{
delete();
}
else if(g=='3')
{
char a[20],b[20];
int t;
double k;
printf("ѡ<EFBFBD><EFBFBD>ɸѡ<EFBFBD>ķ<EFBFBD>ʽ\n1.<2E><><EFBFBD>\n2.<2E><>ѧ<EFBFBD><D1A7>\n3.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n4.<2E><><EFBFBD>ܷ<EFBFBD>\n");
scanf("%d",&t);
nul=getchar();
if(t>=1&&t<=3)
{
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD>ķ<EFBFBD>Χ<EFBFBD><EFBFBD>\nbegin<EFBFBD><EFBFBD>");
scanf("%s",a);
printf("end<EFBFBD><EFBFBD>");
scanf("%s",b);
nul=getchar();
select(a,b,t,0);
}
else if(t==4)
{
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><EFBFBD>ڵ<EFBFBD><EFBFBD>ܷ<EFBFBD>\n");
scanf("%lf\n",k);
nul=getchar();
select(a,b,t,k);
}
}
else if(g=='6')
{
break;
}
else printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
printf("continue?\n");
char s[100];
scanf("%s",s);
nul=getchar();
char* yes="yes";
if(strcmp(s,yes)==0){}
else break;
}
return 0;
}