PTA第9章文件作业9-5 谁是冠军 (10分)

                  9-5 谁是冠军 (10分)

文件查重:若干名选手参加扣篮大赛,共有5个评委,现有一个二进制文件pf.dat,内容为选手参加扣篮大赛决赛的成绩(总分高者获胜),编程找出谁是champion(输出冠军者姓名)。
输出格式:如果冠军是zhangwei,则输出zhangwei is champion!
struct person { char name[20]; int score[5]; };
编写的源程序命名为test.cpp,提交之前,将pf.dat和test.cpp放在src文件夹下,然后在src文件夹的上层文件夹中压缩src.zip,保证这个zip文件中有src文件夹和其中的test.cpp文件。
如果使用WinRAR、7z等压缩软件,请注意压缩文件的格式为zip,而不是压缩为其他格式后修改后缀为zip。目前已知使用Windows的资源管理器的右键菜单中的“发送到压缩(zipped)文件夹“功能产生的zip文件不被PTA所接受。Unix的zip命令压缩的文件夹可以接受。

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct person 
{	char name[20]; 
	int score[5]; 
};
int main()
{
	struct person st[100];
	int i = 0,j,sum,su[100];
	char s[20];
	FILE *fp1;
	if((fp1=fopen("src/pf.dat","rb"))==NULL)
	{
		printf("can't open this file");
	}
	while(fread(&st[i],sizeof(struct person ),1,fp1)==1)
	{
		
		su[i] = st[i].score[0]+st[i].score[1]+st[i].score[2]+st[i].score[3]+st[i].score[4];
	//	printf("%s %d %d %d %d %d %d\n",st[i].name,st[i].score[0],st[i].score[1],st[i].score[2],st[i].score[3],st[i].score[4],su[i]);
		i++;
		
	}
	sum=su[0];
	strcpy(s,st[0].name);
//	printf("%s\n",s);
	for(j=0;j<i;j++)
	{
		if(su[j]>sum)
		{
			sum=su[j];
			strcpy(s,st[j].name);			
		}
	}
	printf("%s is champion!",c);	
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值