Linglong_svip 于 2017.01.01 19:20 提问

#include
int main()
{
typedef struct singer
{
char name[10];
int score[4];
double average;
}sin,t;
sin singer[5];
int i,j,m,n,max,min;
printf("请输入五位歌手及4位评委对其的打分\n");
for(i=0;i<5;i++)
scanf("%s%d%d%d%d",&singer[i].name,&singer[i].score[0],&singer[i].score[1],&singer[i].score[2],&singer[i].score[3]);

//求平均
for(i=0;i {
max=singer[i].score[0];
min=singer[i].score[0];
singer[i].average=(double)singer[i].score[0];
for(j=1;j {
if(max max=singer[i].score[j];
if(min>singer[i].score[j])
min=singer[i].score[j];
singer[i].average+=singer[i].score[j];
}
singer[i].average=(singer[i].average-max-min)/2.0;
}
//排序
for(i=0;i for(j=4;j>i;j--)
if(singer[j].average>singer[j-1].average)
{
t=singer[j];
singer[j]=singer[j-1];
singer[j-1]=t;
** }**

for(i=0;i<3;i++)
{
printf("%s:%.2lf\n",singer[i].name,singer[i].average);
}
}

2个回答

caozhy      2017.01.01 19:32

`````` #include <stdio.h>
typedef struct _singer
{
char name[10];
int score[4];
double average;
} sin;
int main()
{

sin singer[5];
int i,j,m,n,max,min;
printf("请输入五位歌手及4位评委对其的打分\n");
for(i=0;i<5;i++)
scanf("%s%d%d%d%d",&singer[i].name,&singer[i].score[0],&singer[i].score[1],&singer[i].score[2],&singer[i].score[3]);

//求平均
for(i=0;i<5;i++)
{
max=singer[i].score[0];
min=singer[i].score[0];
singer[i].average=(double)singer[i].score[0];
for(j=1;j<4;j++)
{
if(max<singer[i].score[j])
max=singer[i].score[j];
if(min>singer[i].score[j])
min=singer[i].score[j];
singer[i].average+=singer[i].score[j];
}
singer[i].average=(singer[i].average-max-min)/2.0;
}
//排序
for(i=0;i<5;i++)
for(j=4;j>i;j--)
if(singer[j].average>singer[j-1].average)
{
sin t=singer[j];
singer[j]=singer[j-1];
singer[j-1]=t;
}

for(i=0;i<3;i++)
{
printf("%s:%.2lf\n",singer[i].name,singer[i].average);
}
}
``````
caozhy 回复Linglong_svip: 就是你错的地方，有好几个

Linglong_svip 这是改什么地方了 ？

YXTS122   2017.01.01 22:51

typedef struct singer
{
}sin,t;