1036 Boys vs Girls (25分)

 

 1 #include <iostream>
 2 #include <cstdio>
 3 using namespace std;
 4 struct node
 5 {
 6     char name[20];
 7     char gender;
 8     char id[20];
 9     int grade;
10 };
11 int main()
12 {
13     int k;
14     cin >> k;
15     struct node temp,p1,p2; //p1存M最小,p2存F最大
16     p1.grade = 101;
17     p2.grade = -1;
18     while(k--)
19     {
20         scanf("%s %c %s %d",temp.name, &temp.gender, temp.id, &temp.grade);
21         if(temp.gender == 'M' && temp.grade < p1.grade)
22             p1 = temp;
23         if(temp.gender == 'F' && temp.grade > p2.grade)
24             p2 = temp;
25     }
26         if( p2.grade != -1)     printf("%s %s\n",p2.name, p2.id);
27             else   printf("Absent\n");
28         if( p1.grade != 101)    printf("%s %s\n",p1.name, p1.id);
29             else    printf("Absent\n");
30         if( p1.grade != 101 &&  p2.grade != -1)
31             printf("%d",p2.grade-p1.grade);
32             else    printf("NA");
33     return 0;
34 }

 

posted @ 2020-06-21 10:23  幻想Elapse  阅读(143)  评论(0编辑  收藏  举报