#include <stdio.h>
#include <stdlib.h>
struct student{

        int english;
        int chinese;
        int math;
        int physics;
        char name[20];
    };
void getHighestGrade(struct student*);
void getNoPassGrade(struct student*);
void getAvgGrade(struct student*);
int main()
{
    int loop;

    struct student studentA[5];
    for(loop=0;loop<5;loop++){
        printf("請輸入學生名字:");
        scanf("%s",&studentA[loop].name);
        printf("請輸入英文成績:");
        scanf("%d",&studentA[loop].english);
        printf("請輸入國文成績:");
        scanf("%d",&studentA[loop].chinese);
        printf("請輸入數學成績:");
        scanf("%d",&studentA[loop].math);
        printf("請輸入物理成績:");
        scanf("%d",&studentA[loop].physics);
    }
    printf("------------ans1-----------\n");
    for(loop=0;loop<5;loop++){
        printf("%s\t英文:%d,中文:%d,數學:%d,物理:%d\n",studentA[loop].name,studentA[loop].english,studentA[loop].chinese,studentA[loop].math,studentA[loop].physics);
    }
    getHighestGrade(&studentA);
    getNoPassGrade(&studentA);
    getAvgGrade(&studentA);
    return 0;
}
void getHighestGrade(struct student*strStudent){
    int loop,loop1;
    int a=0;
    for(loop=0;loop<4;loop++){
        for(loop1=0;loop1<4-loop;loop1++){
            if(strStudent[loop1].english>strStudent[loop1+1].english){
                a=strStudent[loop1].english;
                strStudent[loop1].english=strStudent[loop1+1].english;
                strStudent[loop1+1].english=a;
            }
        }
    }
    for(loop=0;loop<4;loop++){
        for(loop1=0;loop1<4-loop;loop1++){
            if(strStudent[loop1].chinese>strStudent[loop1+1].chinese){
                a=strStudent[loop1].chinese;
                strStudent[loop1].chinese=strStudent[loop1+1].chinese;
                strStudent[loop1+1].chinese=a;
            }
        }
    }
    for(loop=0;loop<4;loop++){
        for(loop1=0;loop1<4-loop;loop1++){
            if(strStudent[loop1].math>strStudent[loop1+1].math){
                a=strStudent[loop1].math;
                strStudent[loop1].math=strStudent[loop1+1].math;
                strStudent[loop1+1].math=a;
            }
        }
    }
    for(loop=0;loop<4;loop++){
        for(loop1=0;loop1<4-loop;loop1++){
            if(strStudent[loop1].physics>strStudent[loop1+1].physics){
                a=strStudent[loop1].physics;
                strStudent[loop1].physics=strStudent[loop1+1].physics;
                strStudent[loop1+1].physics=a;
            }
        }
    }
    printf("英文最高分=%d\n",strStudent[4].english);
    printf("中文最高分=%d\n",strStudent[4].chinese);
    printf("數學最高分=%d\n",strStudent[4].math);
    printf("物理最高分=%d\n",strStudent[4].physics);
}
void getNoPassGrade(struct student*strStudent){
    int loop;
    printf("英文不及格:");
    for(loop=0;loop<5;loop++){
        if(strStudent[loop].english<60){
                printf("%s",strStudent[loop].name);
        }
    }
    printf("\n");
    printf("國文不及格:");
    for(loop=0;loop<5;loop++){
        if(strStudent[loop].chinese<60){
                printf("%s",strStudent[loop].name);
        }

    }
    printf("\n");
    printf("數學不及格:");
    for(loop=0;loop<5;loop++){
        if(strStudent[loop].math<60){
                printf("%s",strStudent[loop].name);
        }

    }
    printf("\n");
    printf("物理不及格:");
    for(loop=0;loop<5;loop++){
        if(strStudent[loop].physics<60){
                printf("%s",strStudent[loop].name);
        }
    }
    printf("\n");
    }
void getAvgGrade(struct student*strStudent){
    float avgenglish=0;
    float avgchinese=0;
    float avgmath=0;
    float avgphysics=0;
    int loop;
    for(loop=0;loop<5;loop++){
        avgenglish += strStudent[loop].english;
        avgchinese += strStudent[loop].chinese;
        avgmath += strStudent[loop].math;
        avgphysics += strStudent[loop].physics;
    }
    printf("英文平均成績:%.2f\n",avgenglish/5);
    printf("國文平均成績:%.2f\n",avgchinese/5);
    printf("數學平均成績:%.2f\n",avgmath/5);
    printf("物理平均成績:%.2f\n",avgphysics/5);


}