解题思路:
注意事项:
参考代码:
#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 人评分
简单的a+b (C语言代码)浏览:787 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:580 |
C语言训练-列出最简真分数序列* (C语言代码)浏览:537 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:778 |
WU-蓝桥杯算法提高VIP-企业奖金发放 (C++代码)浏览:1240 |
Wu-求圆的面积 (C++代码)浏览:1987 |
母牛的故事 (C语言代码)浏览:1446 |
C语言程序设计教程(第三版)课后习题8.8 (C语言代码)浏览:574 |
1025题解浏览:787 |
C语言程序设计教程(第三版)课后习题11.3 (C语言代码)浏览:640 |