zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    关于JS动态切换样式表
    关于header()函数重定向的问题
    微信团队讲课笔记 Android 开发(二)UI设计
    Effective C++ 笔记:4设计与声明
    某面试算法题_最短时间找出十包粉末中的两蓝粉末。
    VS2015 配置opengl的一些库
    URAL 1225 Flags 简单DP,一重循环
    POJ 1384 Piggy-Bank 完全背包分析
    POJ 1651 Multiplication Puzzle DP 类似矩阵链
    URAL 1183 Brackets Sequence DP 路径输出
  • 原文地址:https://www.cnblogs.com/wydxry/p/11172899.html
Copyright © 2011-2022 走看看