zoukankan      html  css  js  c++  java
  • PAT 1036

     1 #include <vector>
     2 #include <string>
     3 #include <iostream>
     4 #include <fstream>
     5 
     6 using namespace std;
     7 
     8 #define OJ
     9 
    10 #ifdef OJ
    11 #define fin cin
    12 #endif
    13 
    14 struct Student{
    15     string name;
    16     bool is_male;
    17     string id;
    18     int grade;
    19 };
    20 
    21 int main(){
    22 #ifndef OJ
    23     ifstream fin("in.data");
    24 #endif
    25 
    26     int N;
    27     fin >> N;
    28 
    29     vector<Student> students;
    30     for (int i = 0; i < N; i++){
    31         Student stu;
    32         fin >> stu.name;
    33 
    34         char gender;
    35         fin >> gender;
    36 
    37         stu.is_male = (gender == 'M' ? true : false);
    38 
    39         fin >> stu.id;
    40         fin >> stu.grade;
    41 
    42         students.push_back(stu);
    43     }
    44 
    45     int male_grade = 101;
    46     int femail_grade = -1;
    47     int male_idx, femail_idx;
    48     for (int i = 0; i < N; i++){
    49         Student &stu = students[i];
    50         if (stu.is_male){
    51             if (stu.grade < male_grade){
    52                 male_grade = stu.grade;
    53                 male_idx = i;
    54             }
    55         }
    56         else if (stu.grade > femail_grade){
    57             femail_grade = stu.grade;
    58             femail_idx = i;
    59         }
    60     }
    61 
    62     bool na = false;
    63     if (femail_grade == -1){
    64         cout << "Absent" << endl;
    65         na = true;
    66     }
    67     else {
    68         cout << students[femail_idx].name << " " << students[femail_idx].id << endl;
    69     }
    70     if (male_grade == 101){
    71         cout << "Absent" << endl;
    72         na = true;
    73     }
    74     else {
    75         cout << students[male_idx].name << " " << students[male_idx].id << endl;
    76     }
    77     
    78 
    79     if (na){
    80         cout << "NA" << endl;
    81     }
    82     else {
    83         cout << femail_grade - male_grade << endl;
    84     }
    85 
    86     return 0;
    87 }

    题目不难

  • 相关阅读:
    supervisor启动错误解决(二)
    删除文件某行
    离线安装
    docker中/var/lib/docker目录迁移
    if else 使用
    Django views函数添加装饰器
    Netty4
    Fast DFS(二)
    Fast DFS(一)
    SpringBoot和app之间跨域问题
  • 原文地址:https://www.cnblogs.com/EpisodeXI/p/4096046.html
Copyright © 2011-2022 走看看