Maplewing

5/15 C: Structure - student

May 14th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.67 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. typedef struct Student{
  4.     int id;  //學生座號
  5.     int english; //學生英文成績
  6.     int chinese; //學生中文成績
  7.     int math; //學生數學成績
  8. } Student;
  9.  
  10.  
  11. int main(){
  12.     int n;
  13.     scanf("%d", &n);
  14.    
  15.     Student s[1000];
  16.     int i;
  17.     for( i = 0 ; i < n ; i++ ){
  18.         scanf("%d%d%d%d", &s[i].id,
  19.                           &s[i].english,
  20.                           &s[i].chinese,
  21.                           &s[i].math );
  22.     }
  23.    
  24.     int maxStudent = 0;
  25.     for( i = 1 ; i < n ; i++ ){
  26.         if( s[i].english + s[i].chinese + s[i].math >
  27.             s[maxStudent].english + s[maxStudent].chinese + s[maxStudent].math ){
  28.             maxStudent = i;
  29.         }
  30.     }
  31.    
  32.     printf("%d\n", s[maxStudent].id);
  33.    
  34.    
  35.     return 0;
  36. }
Add Comment
Please, Sign In to add comment