1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
#include<cstring> struct { char name[20]; char gender[20]; char ID[20]; int grade; } male, female, temp;
bool great(Student stu1, Student stu2) { if(stu1.grade != stu2.grade) { return stu1.grade > stu2.grade; } }
int main() { int N; scanf("%d", &N); int count_M = 0; int count_F = 0; strcpy(male.name, "abc"); strcpy(male.gender, "M"); strcpy(male.ID, "cs101"); male.grade = 100; strcpy(female.name, "abc"); strcpy(female.gender, "F"); strcpy(female.ID, "CS101"); female.grade = 0; for(int i = 0; i < N; i++) { scanf("%s %s %s %d", &temp.name, &temp.gender, &temp.ID, &temp.grade); if(strcmp(temp.gender, "M") == 0) { if(great(temp, male) == false) { male = temp; } count_M++; } if(strcmp(temp.gender, "F") == 0) { if(great(temp, female) == true) { female = temp; } count_F++; } } if(count_M == 0 || count_F == 0) { if(count_F == 0 && count_M == 0) { printf("Absentn"); printf("Absentn"); printf("NAn"); } if(count_F == 0 && count_M != 0) { printf("Absentn"); printf("%s %sn", male.name, male.ID); printf("NA"); } if(count_F != 0 && count_M == 0) { printf("%s %sn", female.name, female.ID); printf("Absentn"); printf("NA"); } } else { int dif = female.grade - male.grade; printf("%s %sn", female.name, female.ID); printf("%s %sn", male.name, male.ID); printf("%d", dif); } return 0; }
|
近期评论