1036 Boys vs Girls (25point(s)) Easy only once *sort cmp水题

Posted songlinxuan

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了1036 Boys vs Girls (25point(s)) Easy only once *sort cmp水题相关的知识,希望对你有一定的参考价值。

基本思想:

还是sort cmp那一套;

 

关键点:

没啥可说的;

 

 1 #include<iostream>
 2 #include<stdlib.h>
 3 #include<stdio.h>
 4 #include<vector> 
 5 #include<string>
 6 #include<math.h>
 7 #include<algorithm>
 8 using namespace std;
 9 using std::vector;
10 int n;
11 
12 struct student{
13     char name[11];
14     char gender;
15     char id[11];
16     int grade;
17 };
18 
19 vector<student>fe;
20 vector<student>me;
21 bool flag = true;
22 
23 bool cmp(student a, student b) {
24     if (flag) {
25         return a.grade > b.grade;
26     }
27     else {
28         return a.grade < b.grade;
29     }
30 }
31 
32 
33 int main() {
34     scanf("%d", &n);
35     char name[11];
36     char gender;
37     char id[11];
38     int grade;
39     for (int i = 0; i < n; i++) {
40         student s;
41         scanf("%s %c %s %d", s.name, &s.gender, s.id, &s.grade);
42         if (s.gender == M) {
43             me.push_back(s);
44         }
45         else {
46             fe.push_back(s);
47         }
48     }
49     sort(fe.begin(), fe.end(), cmp);
50     flag = false;
51     sort(me.begin(), me.end(), cmp);
52     if (fe.size() == 0) {
53         cout << "Absent" << endl;
54     }
55     else {
56         printf("%s %s
", fe[0].name, fe[0].id);
57     }
58     if (me.size() == 0) {
59         cout << "Absent" << endl;
60     }
61     else {
62         printf("%s %s
", me[0].name, me[0].id);
63     }
64     if(fe.size() == 0 || me.size() == 0) {
65         cout << "NA" << endl;
66     }
67     else {
68         cout << abs(fe[0].grade - me[0].grade)<<endl;
69     }
70     system("pause");
71     return 0;
72 }

以上是关于1036 Boys vs Girls (25point(s)) Easy only once *sort cmp水题的主要内容,如果未能解决你的问题,请参考以下文章

1036. Boys vs Girls (25)

1036. Boys vs Girls (25)

1036 Boys vs Girls (25 分)

PAT 1036 Boys vs Girls (25 分)

PAT甲级:1036 Boys vs Girls (25分)

PAT 甲级 1036 Boys vs Girls (25 分)(简单题)