• PAT (Advanced Level) Practice 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 <iostream>
     2 #include <string>
     3 #include <cstring>
     4 #include <algorithm>
     5 using namespace std;
     6 struct node
     7 {
     8     string name;
     9     char sex;
    10     string id;
    11     int score;
    12 }a[1005];
    13 int main()
    14 {
    15     int n;
    16     while(cin>>n){
    17         int num_M=0,num_F=0;
    18         int index_M=0,index_F=0;
    19         int min_M=10000,max_F=0;
    20         for(int i=0;i<n;i++){
    21             cin>>a[i].name>>a[i].sex>>a[i].id>>a[i].score;
    22             if(a[i].sex=='M'){
    23                 num_M++;
    24                 if(a[i].score<min_M){
    25                     index_M=i;
    26                     min_M=a[i].score;
    27                 }
    28             }else if(a[i].sex=='F'){
    29                 num_F++;
    30                 if(a[i].score>max_F){
    31                     index_F=i;
    32                     max_F=a[i].score;
    33                 }
    34             }
    35             
    36         }
    37         if(num_F==0){
    38             cout<<"Absent"<<endl;
    39         }else{
    40             cout<<a[index_F].name<<" "<<a[index_F].id<<endl;
    41         }
    42         if(num_M==0){
    43             cout<<"Absent"<<endl;
    44         }else{
    45             cout<<a[index_M].name<<" "<<a[index_M].id<<endl;
    46         }
    47         if(num_M==0||num_F==0){
    48             cout<<"NA"<<endl;
    49         }else{
    50             cout<<a[index_F].score-a[index_M].score<<endl;
    51         }
    52     }
    53     return 0;
    54 }
  • 相关阅读:
    收藏了!主流应用市场产品提交资料汇总!
    Oracle用户、权限、角色管理
    H3C SNMP配置解析
    从实战角度浅析snmp
    ICE checkbox 用法
    eclipse序列化生成serialVersionUID
    Bat命令学习
    app生成工具
    微软浏览器兼容工具modern.IE
    php判断手机客户端
  • 原文地址:https://www.cnblogs.com/wydxry/p/11172899.html
Copyright © 2020-2023  润新知