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.
134 lines
2.8 KiB
134 lines
2.8 KiB
#include <stdio.h>
|
|
#include <string.h>
|
|
struct stud
|
|
{
|
|
int num;
|
|
int clas;
|
|
char name[10];
|
|
float math;
|
|
float phy;
|
|
float eng;
|
|
}t={};
|
|
int main()
|
|
{
|
|
struct stud stu[10]={{10001,11,"Zhang",99.5,88.5,89.5},
|
|
{10002,12,"Yang",77.9,56.5,87.5},
|
|
{10003,11,"Liang",92.5,99.0,60.},
|
|
{10004,11,"Cai",89.6,56.9,90.5},
|
|
{10005,14,"Fu",55.6,67.9,98.9},
|
|
{10006,12,"Mao",22.1,45.9,99.2},
|
|
{10007,13,"Zhan",35.6,67.9,88.0}
|
|
};
|
|
struct stud *p=stu;
|
|
void range(struct stud stu[]);
|
|
range(p);
|
|
void getclass(struct stud stu[]);
|
|
void getnum(struct stud stu[]);
|
|
void getname(struct stud stu[]);
|
|
void getgrade(struct stud stu[]);
|
|
void getclnum(struct stud stu[]);
|
|
int way;
|
|
scanf("%d",&way);
|
|
switch(way)
|
|
{
|
|
case 1:getclass(p);break;
|
|
case 2:getnum(p);break;
|
|
case 3:getname(p);break;
|
|
case 4:getgrade(p);break;
|
|
case 5:getclnum(p);break;
|
|
|
|
}
|
|
return 0;
|
|
}
|
|
void range(struct stud stu[])
|
|
{
|
|
int i,j;
|
|
for(i=0;stu[i].num!=0;i++)
|
|
{
|
|
if(stu[i+1].num!=0)
|
|
{
|
|
for(j=i+1;stu[j].num!=0;j++)
|
|
{
|
|
if(stu[i].clas>stu[j].clas)
|
|
{
|
|
t=stu[i];stu[i]=stu[j];stu[j]=t;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
for(i=0;stu[i].num!=0;i++)
|
|
{
|
|
if(stu[i+1].num!=0)
|
|
{
|
|
for(j=i+1;stu[j].num!=0&&stu[i].clas==stu[j].clas;j++)
|
|
{
|
|
if(stu[i].math+stu[i].phy+stu[i].eng<stu[j].math+stu[j].phy+stu[j].eng)
|
|
{
|
|
t=stu[i];stu[i]=stu[j];stu[j]=t;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
void getclass(struct stud stu[])
|
|
{
|
|
int a,b,i;
|
|
char c;
|
|
scanf("%d %c %d",&a,&c,&b);
|
|
for(i=0;stu[i].num!=0;i++)
|
|
{
|
|
if(a<=stu[i].clas&&stu[i].clas<=b)
|
|
printf("%d %d %s %3.1f %3.1f %3.1f\n",stu[i].num,stu[i].clas,stu[i].name,stu[i].math,stu[i].phy,stu[i].eng);
|
|
}
|
|
}
|
|
void getnum(struct stud stu[])
|
|
{
|
|
int a,b,i;
|
|
char c;
|
|
scanf("%d %c %d",&a,&c,&b);
|
|
for(i=0;stu[i].num!=0;i++)
|
|
{
|
|
if(a<=stu[i].num&&stu[i].num<=b)
|
|
printf("%d %d %s %3.1f %3.1f %3.1f\n",stu[i].num,stu[i].clas,stu[i].name,stu[i].math,stu[i].phy,stu[i].eng);
|
|
}
|
|
}
|
|
void getname(struct stud stu[])
|
|
{
|
|
int i,j;
|
|
char cn[10];
|
|
scanf("%s",cn);
|
|
int l=strlen(cn)-1;
|
|
for(i=0;stu[i].num!=0;i++)
|
|
{
|
|
for(j=0;j<l;j++)
|
|
{
|
|
if(stu[i].name[j]!=cn[j])goto again;
|
|
}
|
|
printf("%d %d %s %3.1f %3.1f %3.1f\n",stu[i].num,stu[i].clas,stu[i].name,stu[i].math,stu[i].phy,stu[i].eng);
|
|
again:;
|
|
}
|
|
}
|
|
void getgrade(struct stud stu[])
|
|
{
|
|
int i;
|
|
float a;
|
|
scanf("%f",&a);
|
|
for(i=0;stu[i].num!=0;i++)
|
|
{
|
|
if(stu[i].math+stu[i].phy+stu[i].eng>=a)
|
|
printf("%d %d %s %3.1f %3.1f %3.1f\n",stu[i].num,stu[i].clas,stu[i].name,stu[i].math,stu[i].phy,stu[i].eng);
|
|
}
|
|
}
|
|
void getclnum(struct stud stu[])
|
|
{
|
|
int a,b,c,i;
|
|
char x,xx;
|
|
scanf("%d %c %d %c %d",&a,&x,&b,&xx,&c);
|
|
for(i=0;stu[i].num!=0;i++)
|
|
{
|
|
if(b<=stu[i].num&&stu[i].num<=c&&stu[i].clas==a)
|
|
printf("%d %d %s %3.1f %3.1f %3.1f\n",stu[i].num,stu[i].clas,stu[i].name,stu[i].math,stu[i].phy,stu[i].eng);
|
|
}
|
|
}
|
|
|