• 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


    #include<bits/stdc++.h>
    using namespace std;
    const int maxn=1010;
    struct node{
        string name;
        char gender;
        string id;
        int grade;
    };
    vector<node> v;
    int main(){
        int n;
        cin>>n;
        v.resize(n);
        int maxF=-1,maxdex=-1;
        int minM=1000000000,mindex=-1;
        for(int i=0;i<n;i++){
            cin>>v[i].name>>v[i].gender>>v[i].id>>v[i].grade;
            if(v[i].gender=='F'&&v[i].grade>maxF){
                maxF=v[i].grade;
                maxdex=i;
            }
            if(v[i].gender=='M'&&v[i].grade<minM){
                minM=v[i].grade;
                mindex=i;
            }
        }
        int cnt;
        
        if(maxdex!=-1&&mindex!=-1){
            cnt=abs(v[maxdex].grade-v[mindex].grade);
            cout<<v[maxdex].name<<" "<<v[maxdex].id<<endl;
            cout<<v[mindex].name<<" "<<v[mindex].id<<endl;
            cout<<cnt<<endl;
        }
        else{
            if(maxdex==-1){
                cout<<"Absent"<<endl;
            }
            else{
                cout<<v[maxdex].name<<" "<<v[maxdex].id<<endl;
            }
            if(mindex==-1){
                cout<<"Absent"<<endl;
            }
            else{
                cout<<v[mindex].name<<" "<<v[mindex].id<<endl;
            }
            if(maxdex==-1||mindex==-1){
                cout<<"NA"<<endl;
            }
        }
        return 0;
    }

     优化:

    #include<bits/stdc++.h>
    using namespace std;
    const int maxn=1010;
    struct node{
        string name;
        char gender;
        string id;
        int grade;
    };
    vector<node> v;
    int main(){
        int n;
        cin>>n;
        v.resize(n);
        int maxF=-1,maxdex=-1;
        int minM=1000000000,mindex=-1;
        for(int i=0;i<n;i++){
            cin>>v[i].name>>v[i].gender>>v[i].id>>v[i].grade;
            if(v[i].gender=='F'&&v[i].grade>maxF){
                maxF=v[i].grade;
                maxdex=i;
            }
            if(v[i].gender=='M'&&v[i].grade<minM){
                minM=v[i].grade;
                mindex=i;
            }
        }
        if(maxdex!=-1){
            cout<<v[maxdex].name<<" "<<v[maxdex].id<<endl;
        }
        else{
            cout<<"Absent"<<endl;
        }
        if(mindex!=-1){
            cout<<v[mindex].name<<" "<<v[mindex].id<<endl;
        }
        else{
            cout<<"Absent"<<endl;
        }
        if(maxdex!=-1&&mindex!=-1){
            int cnt=abs(v[maxdex].grade-v[mindex].grade);
            cout<<cnt<<endl;
        }
        else{
            cout<<"NA"<<endl;
        }
        return 0;
    }
  • 相关阅读:
    SAP MM MIGO过账报错
    SAP MM MB5L事务代码'仅总计'选项初探
    SAP MM 巴西采购订单中的NCM Code
    SAP MM Storage Location Missing in MD04 Result?
    SAP MM 预留单据的历史修改记录?
    2018-8-10-上传代码-CodePlex
    2019-9-2-win10-uwp-九幽图床
    2018-2-13-win10-UWP-应用设置
    2018-2-13-win10-UWP-你写我读
    2018-2-13-win10-UWP-九幽登录
  • 原文地址:https://www.cnblogs.com/dreamzj/p/14461292.html
Copyright © 2020-2023  润新知