zoukankan      html  css  js  c++  java
  • 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 }



  • 相关阅读:
    linux中grep用法(“或”、“与”)
    mac 常用开发软件列表
    Devops实战(四)Rancher的部署与安装详解
    Devops实战(三)Kubenets与minikube的安装以及使用实战
    intel 无线网卡 AC8260 周期性跳ping(高延迟)解决方案
    确定了,回归吧,19,20就当换了换环境,该努力了。
    win10下用Linux搭建python&nodejs开发环境
    pict总结
    移动无线常用测试工具
    游戏测试工具
  • 原文地址:https://www.cnblogs.com/zllwxm123/p/11087821.html
Copyright © 2011-2022 走看看