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
    题目分析:排序题 直接利用STL中sort来写 细心即可
     1 #define _CRT_SECURE_NO_WARNINGS
     2 #include <climits>
     3 #include<iostream>
     4 #include<vector>
     5 #include<queue>
     6 #include<map>
     7 #include<stack>
     8 #include<algorithm>
     9 #include<string>
    10 #include<cmath>
    11 using namespace std;
    12 struct student {
    13     string name, gender, ID;
    14     int grade;
    15 };
    16 bool compare(const student& a, const student& b)
    17 {
    18     return a.grade < b.grade;
    19 }
    20 int main()
    21 {
    22     vector<student> SM;
    23     vector<student>SF;
    24     int N;
    25     cin >> N;
    26     string name, gender, ID;
    27     int grade;
    28     for (int i = 0; i < N; i++)
    29     {
    30         cin >> name >> gender >> ID >> grade;
    31         if (gender == "M")
    32             SM.push_back({ name,gender,ID,grade });
    33         else
    34             SF.push_back({ name,gender,ID,grade });
    35     }
    36     sort(SM.begin(), SM.end(), compare);
    37     sort(SF.begin(), SF.end(), compare);
    38     if (SF.size() == 0 || SM.size() == 0)
    39     {
    40         if (SF.size() == 0)
    41         {
    42             cout << "Absent" << endl;
    43             if (SM.size() == 0)
    44                 cout << "Absent" << endl;
    45             else
    46                 cout << (*SM.begin()).name <<" "<<(*SM.begin()).ID<<endl;
    47         }
    48         else
    49         {
    50             cout << (*(SF.end() - 1)).name << " " << (*(SF.end() - 1)).ID << endl;
    51             if(SM.size()==0)
    52                 cout << "Absent" << endl;
    53         }
    54         cout << "NA";
    55     }
    56     else
    57     {
    58         cout << (*(SF.end() - 1)).name << " " << (*(SF.end() - 1)).ID << endl;
    59         cout << (*SM.begin()).name << " " << (*SM.begin()).ID << endl;
    60         cout << (*(SF.end() - 1)).grade - (*SM.begin()).grade;
    61     }
    62 }
    View Code
  • 相关阅读:
    记一次阿里云硬盘在线扩容
    大文件传输技巧-----split切割
    数据库迁移-------通过ibdata1文件和数据库文件迁移
    小技巧---------------vim 使用技巧 set paste 解决粘贴乱序问题
    webfrom 做项目的注意事项
    webform 复合控件
    wenfrom的简单控件和repeater控件
    分页功能 与 分类查询功能合并
    内置对象2
    简单的人员管理系统
  • 原文地址:https://www.cnblogs.com/57one/p/12013668.html
Copyright © 2011-2022 走看看