A1036 Boys vs Girls (25 points | find elements, with detailed notes, logical analysis)

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/qq_24452475/article/details/100549416

EDITORIAL

  • Ideas analysis
    • string-type female and male student information retention requirements
    • int type fscore and mscore save the boys and girls the highest score lowest score
      • Initialization fscore-1, mscore maximum value 101
      • According to sex, size fraction iterative update:
        • female和male
        • fscore and mscore
  • The title is simple, not repeat them
    • 15 minutes a topic

Test Case

  • input:
    3
    Joe M Math990112 89
    Mike M CS991301 100
    Mary F EE990830 95
    
    output:
    Mary EE990830
    Joe Math990112
    6
    
    input:
    1
    Jean M AA980920 60
    
    output:
    Absent
    Jean AA980920
    NA
    

ac Code

  • #include <iostream>
    using namespace std;
    
    int main()
    {
        int n;
        scanf("%d", &n);
        string female, male;
        int fscore = -1, mscore = 101;
    
        for(int i=0; i<n; i++)
        {
            string name, sex, num;
            int score;
            cin >> name >> sex >> num;
            scanf("%d", &score);
    
            if(sex == "F")
            {
                if(fscore < score)
                {
                    fscore = score;
                    female = name + " " + num;
                }
            }
            else if (mscore > score)
            {
                mscore = score;
                male = name + " " + num;
            }
        }
        if(fscore != -1)
            cout << female << endl;
        else
            printf("Absent\n");
        if(mscore != 101)
            cout << male << endl;
        else
            printf("Absent\n");
        if(mscore != 101 && fscore != -1)
            printf("%d", fscore-mscore);
        else
            printf("NA\n");
    
        return 0;
    }
    

Guess you like

Origin blog.csdn.net/qq_24452475/article/details/100549416