ADD file via upload

main
psc4a9qur 1 week ago
parent 26b245841b
commit cebbc7dc54

152
a7.c

@ -0,0 +1,152 @@
#include <stdio.h>
#include <string.h>
struct stu {
char num[6];
char class[3];
char name[6];
float grade1;
float grade2;
float grade3;
float grade;
}s[10],ss,sss[7];
void f1(struct stu s[],int k)
{
for(int i=0;i<k-1;i++)
{
for(int j=i+1;j<k;j++)
{
if(strcmp(s[i].class,s[j].class)>0)
{
ss=s[i];
s[i]=s[j];
s[j]=ss;
}
}
}
}
void f2(struct stu s[])
{
for(int o=11;o<=14;o++)
{
for(int i=0;s[i].class==o;i++)
{
for(int j=i+1;s[j].class==o;j++)
{
if(s[i].grade<s[j].grade)
{
ss=s[i];
s[i]=s[j];
s[j]=ss;
}
}
}
}
}
void f3(struct stu s[],int k)
{
for(int i=0;i<k;i++)
{
printf("%s %s %s %.1f %.1f %.1f\n",s[i].num,s[i].class,s[i].name,s[i].grade1,s[i].grade2,s[i].grade3);
}
}
int main()
{
strcpy(s[0].num,"10001");strcpy(s[0].class,"11");strcpy(s[0].name,"Zhang");s[0].grade1=99.5;s[0].grade2=88.5;s[0].grade3=89.5;s[0].grade=s[0].grade1+s[0].grade2+s[0].grade3;
strcpy(s[1].num,"10002");strcpy(s[1].class,"12");strcpy(s[1].name,"Yang");s[1].grade1=77.9;s[1].grade2=56.5;s[1].grade3=87.5;s[1].grade=s[1].grade1+s[1].grade2+s[1].grade3;
strcpy(s[2].num,"10003");strcpy(s[2].class,"11");strcpy(s[2].name,"Liang");s[2].grade1=92.5;s[2].grade2=99.0;s[2].grade3=60.5;s[2].grade=s[2].grade1+s[2].grade2+s[2].grade3;
strcpy(s[3].num,"10004");strcpy(s[3].class,"11");strcpy(s[3].name,"Cai");s[3].grade1=89.6;s[3].grade2=56.9;s[3].grade3=90.5;s[3].grade=s[3].grade1+s[3].grade2+s[3].grade3;
strcpy(s[4].num,"10005");strcpy(s[4].class,"14");strcpy(s[4].name,"Fu");s[4].grade1=55.6;s[4].grade2=67.9;s[4].grade3=98.9;s[4].grade=s[4].grade1+s[4].grade2+s[4].grade3;
strcpy(s[5].num,"10006");strcpy(s[5].class,"12");strcpy(s[5].name,"Mao");s[5].grade1=22.1;s[5].grade2=45.9;s[5].grade3=99.2;s[5].grade=s[5].grade1+s[5].grade2+s[5].grade3;
strcpy(s[6].num,"10007");strcpy(s[6].class,"13");strcpy(s[6].name,"Zhan");s[6].grade1=35.6;s[6].grade2=67.9;s[6].grade3=88.0;s[6].grade=s[6].grade1+s[6].grade2+s[6].grade3;
int a;
scanf("%d",&a);
if(a==1)
{
char aa[3],bb[3];
scanf("%s %s",aa,bb);
int k=0;
for(int i=0;i<7;i++)
{
if(strcmp(s[i].class,aa)>=0&&strcmp(s[i].class,bb)<=0)
{
sss[k]=s[i];
k++;
}
}
f1(sss,k);
f2(sss);
f3(sss,k);
}
else if(a==2)
{
char cc[6],dd[6];
scanf("%s %s",cc,dd);
int k=0;
for(int i=0;i<7;i++)
{
if(strcmp(s[i].num,cc)>=0&&strcmp(s[i].num,dd)<=0)
{
sss[k]=s[i];
k++;
}
}
f1(sss,k);
f2(sss);
f3(sss,k);
}
else if(a==3)
{
char hh[10];
scanf("%s",hh);
int len=strlen(hh);
int k=0;
for(int i=0;i<7;i++)
{
if(strncmp(hh,s[i].name,len-1)==0)
{
sss[k]=s[i];
k++;
}
}
f1(sss,k);
f2(sss);
f3(sss,k);
}
else if(a==4)
{
double d;
scanf("%lf",&d);
int k=0;
for(int i=0;i<7;i++)
{
if(s[i].grade>=d)
{
sss[k]=s[i];
k++;
}
}
f1(sss,k);
f2(sss);
f3(sss,k);
}
else if(a==5)
{
char ee[3],ff[6],gg[6];
scanf("%s%s%s",ee,ff,gg);
int k=0;
for(int i=0;i<7;i++)
{
if(strcmp(s[i].class,ee)==0&&strcmp(s[i].num,ff)>=0&&strcmp(s[i].num,gg)<=0)
{
sss[k]=s[i];
k++;
}
}
f1(sss,k);
f2(sss);
f3(sss,k);
}
return 0;
}
Loading…
Cancel
Save