// kadai8-1.c
#include <stdio.h>
#include <malloc.h> //malloc()を使うため
#include <stdlib.h> //exit(1)を使うため
struct each_score {
int ten; //点数
int gou; //合格・不合格
};
struct SEISEKI {
char name[50];
struct each_score kokugo;
struct each_score sugaku;
};
void check_score(int borderline, struct SEISEKI *a)
{
a->kokugo.gou = (a->kokugo.ten < borderline) ? 0 : 1;
a->sugaku.gou = (a->sugaku.ten < borderline) ? 0 : 1;
}
void print_score(struct SEISEKI a)
{
char *gou[] = {"rejection","accept"};
printf("name: %s\n", a.name);
printf("kokugo %d : %s\n", a.kokugo.ten, gou[a.kokugo.gou]);
printf("sugaku %d : %s\n", a.sugaku.ten, gou[a.sugaku.gou]);
}
int main()
{
struct SEISEKI *score;
int num;
int i;
printf("Input number of students >\n");
scanf("%d", &num);
score = (struct SEISEKI *)malloc(sizeof(struct SEISEKI) * num);
if (score == NULL) {//メモリ割付に失敗した場合
printf("Memory overflow\n");
exit(1);//異常があったことをOSに伝えて終了する。
}
for (i = 0; i < 3; i++) {
scanf("%49s%d%d", score[i].name, &score[i].kokugo.ten, &score[i].sugaku.ten);
check_score(60, &score[i]);
}
for (i = 0; i < 3; i++) {
print_score(score[i]);
}
return 0;
}
Ly8ga2FkYWk4LTEuYwojaW5jbHVkZSA8c3RkaW8uaD4KI2luY2x1ZGUgPG1hbGxvYy5oPiAgICAvL21hbGxvYygp44KS5L2/44GG44Gf44KBCiNpbmNsdWRlIDxzdGRsaWIuaD4gICAgIC8vZXhpdCgxKeOCkuS9v+OBhuOBn+OCgQoKc3RydWN0IGVhY2hfc2NvcmUgewogICAgIGludCAgdGVuOyAgIC8v54K55pWwCiAgICAgaW50ICBnb3U7ICAgIC8v5ZCI5qC844O75LiN5ZCI5qC8Cn07CgpzdHJ1Y3QgU0VJU0VLSSB7CiAgICBjaGFyIG5hbWVbNTBdOwogICAgc3RydWN0IGVhY2hfc2NvcmUgIGtva3VnbzsKICAgIHN0cnVjdCBlYWNoX3Njb3JlICBzdWdha3U7Cn07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