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.
253 lines
7.7 KiB
253 lines
7.7 KiB
#include<stdio.h>
|
|
#include<string.h>
|
|
struct student
|
|
{
|
|
char num[10];
|
|
float Math;
|
|
float Physic;
|
|
float English;
|
|
float sum;
|
|
float ave;
|
|
int clas;
|
|
int inserted;//sign whether the student is inserted
|
|
char name[10];
|
|
int mod;//sign whether the student is modified
|
|
};
|
|
void outputstudent4(struct student *t)// output num,class,name,and grade of all subject
|
|
{
|
|
printf("%s %d %s %.1f %.1f %.1f\n",t->num,t->clas,t->name,t->Math,t->Physic,t->English);
|
|
}
|
|
void orderstudent2(struct student *t,int n)//order with class
|
|
{
|
|
for(int i=0;i<n;i++)
|
|
{
|
|
for(int j=i;j<n;j++)
|
|
{
|
|
if((t+i)->clas>(t+j)->clas)
|
|
{
|
|
struct student m;
|
|
m=*(t+i);
|
|
*(t+i)=*(t+j);
|
|
*(t+j)=m;
|
|
}
|
|
}
|
|
}
|
|
for(int i=0;i<n;i++)
|
|
{
|
|
for(int j=i;j<n;j++)
|
|
{
|
|
if((t+i)->clas==(t+j)->clas&&(t+i)->sum<(t+j)->sum)
|
|
{
|
|
struct student m;
|
|
m=*(t+i);
|
|
*(t+i)=*(t+j);
|
|
*(t+j)=m;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
void findstudent(struct student *t)
|
|
{
|
|
char c[30];
|
|
fgets(c,sizeof(c),stdin);
|
|
if(c[0]=='1')
|
|
{
|
|
int beginclass=0;
|
|
int i=1;
|
|
while(c[i]!='-')
|
|
{
|
|
if(c[i]>='0'&&c[i]<='9')
|
|
{
|
|
beginclass*=10;
|
|
beginclass+=c[i]-'0';
|
|
}
|
|
i++;
|
|
}
|
|
int finalclass=0;
|
|
int j=i+1;
|
|
while(c[j]>='0'&&c[j]<='9')
|
|
{
|
|
finalclass*=10;
|
|
finalclass+=c[j]-'0';
|
|
j++;
|
|
}
|
|
for(int i=0;i<7;i++)
|
|
{
|
|
if((t+i)->clas>=beginclass&&(t+i)->clas<=finalclass)
|
|
outputstudent4((t+i));
|
|
}
|
|
}
|
|
if(c[0]=='2')
|
|
{
|
|
char beginnum[10]={'\0'};
|
|
int i=1,x=0;
|
|
while(c[i]!='-')
|
|
{
|
|
if(c[i]>='0'&&c[i]<='9')
|
|
{
|
|
beginnum[x]=c[i];
|
|
x++;
|
|
}
|
|
i++;
|
|
}
|
|
char finalnum[10]={'\0'};
|
|
int j=i+1,y=0;
|
|
while(c[j]>='0'&&c[j]<='9')
|
|
{
|
|
finalnum[y]=c[j];
|
|
y++;
|
|
j++;
|
|
}
|
|
for(int m=0;m<7;m++)
|
|
{
|
|
if(strcmp((t+m)->num,beginnum)>=0&&strcmp((t+m)->num,finalnum)<=0)
|
|
outputstudent4((t+m));
|
|
}
|
|
}
|
|
if(c[0]=='3')
|
|
{
|
|
char f[10]={'\0'};
|
|
int i=1,x=0;
|
|
while(c[i]!='*')
|
|
{
|
|
if(c[i]!=' ')
|
|
{
|
|
f[x]=c[i];
|
|
x++;
|
|
}
|
|
i++;
|
|
}
|
|
for(int j=0;j<7;j++)
|
|
{
|
|
if(strncmp((t+j)->name,f,x)==0)
|
|
outputstudent4((t+j));
|
|
}
|
|
}
|
|
if(c[0]=='4')
|
|
{
|
|
float s=0;
|
|
int i=1;
|
|
while(c[i]!='.')
|
|
{
|
|
if(c[i]>='0'&&c[i]<='9')
|
|
{
|
|
s=s*10;
|
|
s+=c[i]-'0';
|
|
}
|
|
i++;
|
|
}
|
|
int j=i+1,n=10;
|
|
while(c[j]>='0'&&c[j]<='9')
|
|
{
|
|
s+=(1.0*(c[j]-'0'))/(1.0*n);
|
|
n=n*10;
|
|
j++;
|
|
}
|
|
for(int x=0;x<7;x++)
|
|
{
|
|
if((t+x)->sum>=s)
|
|
outputstudent4((t+x));
|
|
}
|
|
}
|
|
if(c[0]=='5')
|
|
{
|
|
int beginclass=0;
|
|
int m=1;
|
|
while(c[m]!='.')
|
|
{
|
|
if(c[m]>='0'&&c[m]<='9')
|
|
{
|
|
beginclass*=10;
|
|
beginclass+=c[m]-'0';
|
|
}
|
|
m++;
|
|
}
|
|
char beginnum[10]={'\0'};
|
|
int i=m+1,x=0;
|
|
while(c[i]!='-')
|
|
{
|
|
if(c[i]>='0'&&c[i]<='9')
|
|
{
|
|
beginnum[x]=c[i];
|
|
x++;
|
|
}
|
|
i++;
|
|
}
|
|
char finalnum[10]={'\0'};
|
|
int j=i+1,y=0;
|
|
while(c[j]>='0'&&c[j]<='9')
|
|
{
|
|
finalnum[y]=c[j];
|
|
y++;
|
|
j++;
|
|
}
|
|
for(int e=0;e<7;e++)
|
|
{
|
|
if((t+e)->clas==beginclass&&(strcmp((t+e)->num,beginnum)>=0&&strcmp((t+e)->num,finalnum)<=0))
|
|
outputstudent4((t+e));
|
|
}
|
|
}
|
|
}
|
|
int main()
|
|
{
|
|
struct student s[10];
|
|
strcpy(s[0].num,"10001");
|
|
strcpy(s[0].name,"Zhang");
|
|
s[0].clas=11;
|
|
s[0].Math=99.5;
|
|
s[0].Physic=88.5;
|
|
s[0].English=89.5;
|
|
s[0].sum=s[0].Math+s[0].Physic+s[0].English;
|
|
s[0].inserted=0;
|
|
strcpy(s[1].num,"10002");
|
|
strcpy(s[1].name,"Yang");
|
|
s[1].clas=12;
|
|
s[1].Math=77.9;
|
|
s[1].Physic=56.5;
|
|
s[1].English=87.5;
|
|
s[1].sum=s[1].Math+s[1].Physic+s[1].English;
|
|
s[1].inserted=0;
|
|
strcpy(s[2].num,"10003");
|
|
strcpy(s[2].name,"Liang");
|
|
s[2].clas=11;
|
|
s[2].Math=92.5;
|
|
s[2].Physic=99.0;
|
|
s[2].English=60.5;
|
|
s[2].sum=s[2].Math+s[2].Physic+s[2].English;
|
|
s[2].inserted=0;
|
|
strcpy(s[3].num,"10004");
|
|
strcpy(s[3].name,"Cai");
|
|
s[3].clas=11;
|
|
s[3].Math=89.6;
|
|
s[3].Physic=56.9;
|
|
s[3].English=90.5;
|
|
s[3].sum=s[3].Math+s[3].Physic+s[3].English;
|
|
s[3].inserted=0;
|
|
strcpy(s[4].num,"10005");
|
|
strcpy(s[4].name,"Fu");
|
|
s[4].clas=14;
|
|
s[4].Math=55.6;
|
|
s[4].Physic=67.9;
|
|
s[4].English=98.9;
|
|
s[4].sum=s[4].Math+s[4].Physic+s[4].English;
|
|
s[4].inserted=0;
|
|
strcpy(s[5].num,"10006");
|
|
strcpy(s[5].name,"Mao");
|
|
s[5].clas=12;
|
|
s[5].Math=22.1;
|
|
s[5].Physic=45.9;
|
|
s[5].English=99.2;
|
|
s[5].sum=s[5].Math+s[5].Physic+s[5].English;
|
|
s[5].inserted=0;
|
|
strcpy(s[6].num,"10007");
|
|
strcpy(s[6].name,"Zhan");
|
|
s[6].clas=13;
|
|
s[6].Math=35.6;
|
|
s[6].Physic=67.9;
|
|
s[6].English=88.0;
|
|
s[6].sum=s[6].Math+s[6].Physic+s[6].English;
|
|
s[6].inserted=0;
|
|
orderstudent2(&s[0],7);
|
|
findstudent(&s[0]);
|
|
return 0;
|
|
} |