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.

138 lines
2.2 KiB

6 years ago
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct singer
{
char id[10];
int rank;
char name[10];
int score[10];
float mark;
};
int main(void)
{
int i,b,j,s,n,t;
FILE *fp;
int sum,max,min;
struct singer a[5];
printf(" <20><><EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD>ϵͳ \n");
printf(" <20>˵<EFBFBD> \n");
printf("1:<3A><><EFBFBD><EFBFBD>ѡ<EFBFBD>ֱ<EFBFBD><D6B1>ź<EFBFBD><C5BA><EFBFBD><EFBFBD><EFBFBD>\n");
printf("2:<3A><>ί<EFBFBD><CEAF><EFBFBD><EFBFBD>\n");
printf("3:<3A><><EFBFBD><EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD>\n");
printf("4:<3A>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD><EFBFBD>\n");
printf("5:д<><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>\n");
printf("6:<3A><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>\n");
printf("7:<3A>˳<EFBFBD>ϵͳ\n");
printf(" ");
for( ; ;)
{
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
scanf("%d",&n);
switch(n)
{
case 1:
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD>ֱ<EFBFBD><EFBFBD>ź<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
for(i=0;i<5;i++)
{
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>%d<><64>ѡ<EFBFBD>ֵı<D6B5><C4B1>ź<EFBFBD><C5BA><EFBFBD><EFBFBD><EFBFBD>:",i);
scanf("%s %s",a[i].id,a[i].name);
}
break;
case 2:
printf("<EFBFBD><EFBFBD>ί<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
printf("<EFBFBD><EFBFBD><EFBFBD>߷<EFBFBD>Ϊ100<EFBFBD><EFBFBD>\n");
for(i=0;i<5;i++)
{
printf("<EFBFBD><EFBFBD>ί<EFBFBD><EFBFBD>%d<>Ÿ<EFBFBD><C5B8>ִ<EFBFBD><D6B4><EFBFBD>:\n",i);
for(j=0;j<5;j++)
{
printf("%d<><64><EFBFBD><EFBFBD>ί<EFBFBD><CEAF><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD><D6B4><EFBFBD>:",j);
scanf("%d",&a[i].score[j]);
}
}
break;
case 3:
for(i=0;i<5;i++)
{
max=a[i].score[0];
min=a[i].score[0];
sum=0;
for(j=0;j<5;j++)
{
sum=sum+a[i].score[j];
if(a[i].score[j]>max)
{
max=a[i].score[j];
}
if(a[i].score[j]<min)
{
min=a[i].score[j];
}
}
printf("%d<>Ÿ<EFBFBD><C5B8>ֵ<EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD>",i);
a[i].mark=(sum-min-max)/3.0;
printf("%f\n",a[i].mark);
}
break;
case 4:
for(i=0;i<=n;i++)
{
s=0;
for(j=0;j<=n;j++)
{
if(a[i].mark<a[j].mark)
s++;
}
a[i].rank=s;
}
for(i=0;i<=n;i++)
{
for(j=0;j<=n;j++)
{
if(i==a[j].rank)
printf("%s<>ǵ<EFBFBD>%d <20>÷<EFBFBD>Ϊ%.2f\n",a[j].name,i,a[j].mark);
}
printf("\n");
}
break;
case 5:
if((fp=fopen("singer.txt","w"))==NULL)
{
printf("cann't open file");
}
for(i=0;i<5;i++)
{
fwrite(&a[i],sizeof(struct singer),1,fp);
}
fclose(fp);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>\n");
break;
case 6:
if((fp=fopen("singer.txt","rb"))==NULL)
{
printf("cann't open file");
}
for(i=0;i<5;i++)
{
fscanf(fp,"%s %s %f",a[i].id,a[i].name,&a[i].mark);
printf("%s %s %f\n",a[i].id,a[i].name,&a[i].mark);
}
break;
case 7:
exit(0);
}
}
return 0;
}