ADD file via upload

main
pfwtzfkoe 1 year ago
parent 66f7f469ac
commit 6b78a8e18b

154
7.c

@ -0,0 +1,154 @@
#include <stdio.h>
#include <string.h>
struct student{
int n;
int c;
char l[8];
float m;
float p;
float e;
float s;
}stu[7]={{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.5},{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.0,88.0}};
//求和函数
void sum(struct student stu[7])
{
int i;
for(i=0;i<7;i++)
{
stu[i].s=stu[i].m+stu[i].p+stu[i].e;
}
}
// 排序函数
void sort(struct student stu[],int len)
{
int i,j;
for(i=0;i<len;i++)
{
int k=i;
for(j=i;j<len;j++)
{
if(stu[k].c>stu[j].c||(stu[k].c==stu[j].c&&stu[k].s<stu[j].s))
{
k=j;
}
if(k!=i)
{
struct student temp=stu[i];
stu[i]=stu[k];
stu[k]=temp;
}
}
}
for(i=0;i<len;i++)
{
printf("%d %d %s %.1f %.1f %.1f \n",stu[i].n,stu[i].c,stu[i].l,stu[i].m,stu[i].p,stu[i].e);
}
}
void class(int a,int b)
{
struct student temp[7];
int i,j=0;
for(i=0;i<7;i++)
{
if(a<=stu[i].c&&stu[i].c<=b)
temp[j++]=stu[i];
}
sort(temp,j);
}
void number(int a,int b)
{
struct student temp[7];
int i,j=0;
for(i=0;i<7;i++)
{
if(a<=stu[i].n&&stu[i].n<=b)
temp[j++]=stu[i];
}
sort(temp,j);
}
void name(const char* prefix)
{
struct student temp[7];
int i,j = 0;
for (i = 0; i < 7; i++)
{
if (strncmp(prefix, stu[i].l, strlen(prefix)) == 0)
temp[j++] = stu[i];
}
sort(temp, j);
}
void score(int a)
{
struct student temp[7];
int i,j=0;
for(i=0;i<7;i++)
{
if(a<=stu[i].s)
temp[j++]=stu[i];
}
sort(temp,j);
}
void candn(int a,int b,int c)
{
struct student temp1[7],temp2[7];
int i,j=0;
for(i=0;i<7;i++)
{
if(a==stu[i].c)
temp1[j++]=stu[i];
}
int len=j-1;
for(i=0,j=0;i<len;i++)
{
if(b<=temp1[i].n&&temp1[i].n<=c)
temp2[j++]=temp1[i];
}
sort(temp2,j);
}
int main()
{
sum(stu);
char gets=getchar();
//查班级
if(gets=='1')
{
int a,b;
scanf("%d-%d",&a,&b);
class(a,b);
}
//查学号
if(gets=='2')
{
int a,b;
scanf("%d-%d",&a,&b);
number(a,b);
}
//查姓名
if (gets=='3')
{
char prefix[8];
scanf("%s", prefix);
name(prefix);
}
//查分数
if(gets=='4')
{
int a;
scanf("%d",&a);
score(a);
}
//查班级和学号
if(gets=='5')
{
int a,b,c;
scanf("%d.%d-%d",&a,&b,&c);
candn(a,b,c);
}
}
Loading…
Cancel
Save