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
  • 相关阅读:
    微信输入文字和更多切换时不改变下面layout大小
    bitmap1 = bitmap2导致bitmap1不能使用一致报回收错误解决
    Mac下命令行打开Sublime
    android.content.res.Resources$NotFoundException:String resource ID #0x86
    SEGGER RTT STOP/SLEEP 模式下使用
    STM32中用 stop 模式 配合低功耗模式下的自动唤醒(AWU) 能否实现FreeRTOS tickless 模式
    NRF52832 能烧写代码 但是不运行 ,是因为没有烧写协议栈
    NRF52832 Logger module 设置
    jlink RTT 打印 BUG , FreeRTOS 在开启 tickless 模式下 无法使用的问题
    gattAttribute_t 含义 中文解释
  • 原文地址:https://www.cnblogs.com/57one/p/12013668.html
Copyright © 2011-2022 走看看