fork download
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. typedef struct student{
  4. char hao[10];
  5. char name[10];
  6. float score[3];
  7. }stu;
  8. void input(stu *p)
  9. {
  10. scanf("%s %s %f %f %f",p->hao,p->name,&p->score[0],&p->score[1],&p->score[2]);
  11. }
  12. void print(stu *p)
  13. {
  14. printf("%s %s %.f %.f %.f\n",p->hao,p->name,p->score[0],p->score[1],p->score[2]);
  15. }
  16. void anverage(stu *p[],int n)
  17. {
  18. float a[3];
  19. for(int i=0;i<3;i++){
  20. a[i]=0;
  21. for(int j=0;j<n;j++)
  22. {
  23. a[i]+=p[j]->score[i];
  24. }
  25. a[i]=a[i]/n;
  26. printf("%.f ",a[i]);
  27. }
  28. printf("\n");
  29. }
  30. void sum(stu *p[],int n)
  31. {
  32. int s[n];
  33. for(int i=0;i<n;i++)
  34. {
  35. s[i]=0;
  36. for(int j=0;j<3;j++)
  37. {
  38. s[i]+=p[i]->score[j];
  39. }
  40. }
  41. int max=s[0];
  42. int count;
  43. for(int k=1;k<n;k++){
  44. if(max<s[k])
  45. {
  46. max=s[k];
  47. count=k;
  48. }
  49. }
  50. print(p[count]);
  51. }
  52. int main()
  53. {
  54. static int N;
  55. printf("input N:\n");
  56. scanf("%d",&N);
  57. stu *s[N];
  58. for(int i=0;i<N;i++)
  59. {
  60. s[i]=(stu*)malloc(sizeof(stu));
  61. input(s[i]);
  62. }
  63. anverage(s,N);
  64. sum(s,N);
  65. return 0;
  66. }
Success #stdin #stdout 0s 4980KB
stdin
4
1 blue 90 80 70
b clan 80 70 60
c vhje 100 80 100
d cudc 20 10 20
stdout
input N:
72 60 62 
c vhje 100 80 100