结构体 打分信息

#include <stdio.h>
#include <stdlib.h>
#include "string.h"
/*
 * 10个负责打分的人,分值0-100,去掉最高分和最低分,余下8个分数平均分为最终分数
要求:
1 输入50个选手名字,与10个评委打分
2 按最终得分求名次,分一样则名次一样
3 最终结果输出在result.txt,包括姓名,10位评委的打分,最终得分和名次。且上下对齐。
最终得分相同的名次相同。
如四名选手 80 75 75 70 名次 1 2 2 4
 */
#define N 5
struct student
{
    char name[5];
    int score[10];  //10个评委的分
    double endscore;   //最后得分
    int rank;  //名次
};

void reverse(struct student Stu[])
{
    int i,j;
    for(i=0;i<N-1;i++)
    {
        for(j=0;j<N-1-i;j++)
        {
            if(Stu[j].endscore<Stu[j+1].endscore)
            {
                struct student temp=Stu[j];
                Stu[j]=Stu[j+1];
                Stu[j+1]=temp;
            }
        }
    }
}

void sortrank(struct student Stu[])
{
    int i,j;
    for(i=1;i<N;i++){
        Stu[0].rank=1;
        if(Stu[i].endscore==Stu[i-1].endscore)
            Stu[i].rank=Stu[i-1].rank;
        else
            Stu[i].rank=i+1;
    }
}
int main()
{
    int i,j;
    struct student stu[N];
    FILE *fp;
//    FILE *fp;
    if((fp=fopen("result20.txt","w"))==NULL)
    {
        printf("file open error!\n");
        exit(0);
    }

    for(i=0;i<N;i++)
    {
        printf("请输入第%d名人员信息:\n",i);
        scanf("%s",stu[i].name);
        int sum=0,max=0,min=100;  //0-100
        for(j=0;j<10;j++)  //十个评委
        {
            scanf("%d",&stu[i].score[j]);
            sum+=stu[i].score[j];
            if(max<=stu[i].score[j])
                max=stu[i].score[j];
            if(min>=stu[i].score[j])
                min=stu[i].score[j];
        }
        sum=sum-max-min;
        stu[i].endscore=sum/8.0;   //最后得分
    }
    //按照最终得分进行排序
    reverse(stu);
    //先排序,排序好了在按照现有的排序进行排名
    sortrank(stu);
    printf("\n************最后排名如下****************\n");
    //打印到屏幕和文件
    for(i=0;i<N;i++){
        printf("%-10s",stu[i].name);
        fprintf(fp,"%-10s",stu[i].name);
        for(j=0;j<10;j++){
            printf("%-5d",stu[i].score[j]);
            fprintf(fp,"%-5d",stu[i].score[j]);
        }
        printf("%-5lf %5d\n",stu[i].endscore,stu[i].rank);
        fprintf(fp,"%-5lf %-5d\n",stu[i].endscore,stu[i].rank);
    }
    fclose(fp);
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值