解题思路:
注意事项:
参考代码:
#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 人评分
P1002 (C语言代码)浏览:994 |
回文数(一) (C语言代码)浏览:783 |
C语言程序设计教程(第三版)课后习题8.3 (C语言代码)浏览:596 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:354 |
WU-字符串比较 (C++代码)浏览:776 |
WU-printf基础练习2 (C++代码)浏览:2013 |
WU-C语言程序设计教程(第三版)课后习题12.1 (C++代码)浏览:958 |
C语言程序设计教程(第三版)课后习题6.8 (C语言代码)浏览:535 |
C语言程序设计教程(第三版)课后习题8.6 (C语言代码)浏览:582 |
C语言程序设计教程(第三版)课后习题8.8 (C语言代码)浏览:660 |