keheia


私信TA

用户名:dotcpp0671850

访问量:138

签 名:

等  级
排  名 10552
经  验 1042
参赛次数 0
文章发表 7
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:

解题思路:

注意事项:

参考代码:

#include <stdio.h>
#include <stdlib.h>

typedef struct students{
	char *id;
	char *name;
	int score[3];
}St;

St * initSt(){
	int i,j;
	St *temp=(St *)malloc(sizeof(St));
	if(temp==NULL){
		return NULL;
	}
	char sr1[100];
	scanf("%s",&sr1);
	temp->id=(char *)malloc(strlen(sr1)+1);
	if(temp->id==NULL){
		return NULL;
	}
	strcpy(temp->id, sr1);
	char sr2[100];
	scanf("%s",&sr2);
	temp->name=(char *)malloc(strlen(sr2)+1);
	if(temp->name==NULL){
		return NULL;
	}
	strcpy(temp->name, sr2);
	int sr3[3];
	for(i=0;i<3;i++){
		scanf("%d",&sr3[i]);
	}
	
	temp->score[3]=(int *)malloc(sizeof(sr3)*3);
	if(temp->score==NULL){
		return NULL;
	}
	for(i=0;i<3;i++){
		temp->score[i]=sr3[i];
	}
	
	return temp;
}


void printStu(St *stu)
{
    printf("%s %s %d %d %d\n", stu->id, stu->name, stu->score[0], stu->score[1] ,stu->score[2]);
}

void freeStu(St *stu)
{
    if (stu == NULL)
        return;
 
    free(stu->id);
    free(stu->name);
    free(stu);
}


int main (){
	int i,j,n,a=0,b=0,c=0,max=0,z=0;
	scanf("%d",&n);
	St *test[n];
	St *test1;
	test1=test[0];
	for (i=0;i<n;i++){
		test[i]=initSt();
	}
   //2 打印
   
    for (i = 0; i < n; i++)
    {
        a+=test[i]->score[0];
        b+=test[i]->score[1];
        c+=test[i]->score[2];
        for(j=0;j<3;j++){
        	max+=test[i]->score[j];
		}
		if(max>z){
			z=max;
			max=0;
			test1=test[i];
		}
    }
 	printf("%d %d %d\n",a/n,b/n,c/n);
 	printStu(test1);
    //3 释放
    for (i = 0; i < n; i++)
    {
        freeStu(test[i]);
    }
	
	
	return 0;
}


 

0.0分

1 人评分

  评论区