• 1036 Boys vs Girls (25 分)


    1036 Boys vs Girls (25 分)
     

    This time you are asked to tell the difference between the lowest grade of all the male students and the highest grade of all the female students.

    Input Specification:

    Each input file contains one test case. Each case contains a positive integer N, followed by N lines of student information. Each line contains a student's namegenderID and grade, separated by a space, where name and ID are strings of no more than 10 characters with no space, gender is either F (female) or M (male), and grade is an integer between 0 and 100. It is guaranteed that all the grades are distinct.

    Output Specification:

    For each test case, output in 3 lines. The first line gives the name and ID of the female student with the highest grade, and the second line gives that of the male student with the lowest grade. The third line gives the difference gradeF​​gradeM​​. If one such kind of student is missing, output Absent in the corresponding line, and output NA in the third line instead.

    Sample Input 1:

    3
    Joe M Math990112 89
    Mike M CS991301 100
    Mary F EE990830 95
    

    Sample Output 1:

    Mary EE990830
    Joe Math990112
    6
    

    Sample Input 2:

    1
    Jean M AA980920 60
    

    Sample Output 2:

    Absent
    Jean AA980920
    NA

    水题不解释

     1 #include <bits/stdc++.h>
     2 #define N 10000
     3 using namespace std;
     4 int n;
     5 struct Node{
     6     string name, id;
     7     int score;
     8 }man[N],women[N];
     9 int ma = 0, fa = 0;
    10 bool cmp1(Node a, Node b){
    11     return a.score < b.score;
    12 }
    13 bool cmp2(Node a, Node b){
    14     return a.score > b.score;
    15 }
    16 
    17 int main(){
    18     cin >> n;
    19     string s1,s3;
    20     char c;
    21     int an;
    22     for(int i = 0; i < n; i++){
    23         cin >> s1 >> c >> s3 >> an;
    24         if(c == 'M'){
    25             man[ma].name = s1;
    26             man[ma].id = s3;
    27             man[ma++].score = an;
    28         }else{
    29             women[fa].name = s1;
    30             women[fa].id = s3;
    31             women[fa++].score = an;
    32         }
    33     }
    34     sort(man,man+ma,cmp1);
    35     sort(women,women+fa,cmp2);
    36     if(ma && fa){
    37         cout << women[0].name << " " <<women[0].id<<endl;
    38         cout << man[0].name << " " << man[0].id << endl;
    39         cout << women[0].score - man[0].score << endl;
    40     }else if(ma){
    41         cout <<"Absent" << endl;
    42         cout << man[0].name << " " << man[0].id << endl;
    43         cout << "NA"<<endl;
    44     }else{
    45         cout << women[0].name << " " <<women[0].id<<endl;
    46         cout <<"Absent" << endl;
    47         cout << "NA"<<endl;
    48     }
    49 
    50 
    51     return 0;
    52 }



  • 相关阅读:
    趣学算法:一场说走就走的旅行 (最短路)
    趣学算法:一场说走就走的旅行 (最短路)
    计蒜客:节食的限制(01背包)
    计蒜客:节食的限制(01背包)
    计蒜客:箱子剩余空间(01背包)
    计蒜客:箱子剩余空间(01背包)
    计蒜客:汽车费用(完全背包)
    计蒜客:汽车费用(完全背包)
    计蒜客: 等和的分隔子集 (01背包)
    .Cannot create an NSPersistentStoreCoordinator with a nil model
  • 原文地址:https://www.cnblogs.com/zllwxm123/p/11087821.html
Copyright © 2020-2023  润新知