//動態配置結構陣列，
//先輸入人數，再依序輸入n個人的姓名、身高、體重
//輸出身高及體重平均
//輸出身高或體重任一項低於平均的人姓名
 
#include <stdio.h>
#include <stdlib.h>
 
struct student{
        char name[21]; 
        int height, weight;
        };
 
int main(){
        int i, n, z, u;
        double t = 10000.00;
        double s = 10000.00;
        double sum_height, sum_weight, Height_avg, Weight_avg;
        sum_height = 0;
        sum_weight = 0;
 
        printf("請輸入人數: \n"); 
        scanf("%d", &n);
 
        struct student *a = (struct student *)malloc(sizeof(struct student)*n);
 
        for (i = 0; i < n; i++){
            printf("請輸入姓名:\n");
            scanf("%s",a[i].name);
            printf("請輸入身高:\n");
            scanf("%d",&a[i].height);
            printf("請輸入體重:\n");
            scanf("%d",&a[i].weight);
    }
 
        for (i = 0; i < n; i++){
        sum_height += a[i].height;
        sum_weight += a[i].weight;
        }
 
        Height_avg = sum_height / n;
        Weight_avg = sum_weight / n;
 
        printf("H_avg: %.2lf\n", Height_avg);
        printf("W_avg: %.2lf\n", Weight_avg);
 
        for (i = 0; i < n; i++){
                if(a[i].height < t){
                    t = a[i].height;
                    z = i;
                }
                if(a[i].weight < s){
                    s = a[i].weight;
                    u = i;
                }
        }
 
        if (a[i].height < Height_avg || a[i].weight < Weight_avg){
            printf("%s", a[z].name);
            printf("%s", a[u].name);
        }
 
        free(a);
        system("pause");
        return 0;
}