zoukankan      html  css  js  c++  java
  • PAT1036:Boys vs Girls

    1036. Boys vs Girls (25)

    时间限制
    400 ms
    内存限制
    65536 kB
    代码长度限制
    16000 B
    判题程序
    Standard
    作者
    CHEN, Yue

    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 name, gender, ID 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<iostream>
    #include<vector>
    #include<string>
    using namespace std;
    
    int main()
    {
        int N;
        while(cin >> N)
        {
            vector<string> lowestmale(4);
            vector<string> highestfemale(4);
            string name,sex,subject,grade;
            for(int i = 0; i < N;i++)
            {
                cin >> name >> sex >> subject >> grade;
                if(sex == "M")
                {
                   if(lowestmale[3] == "" || (lowestmale[3] != "" && stoi(lowestmale[3]) > stoi(grade)))
                   {
                       //如果是第一次输入或者这一次输入的成绩比以往更低
                       lowestmale[0] = name;
                       lowestmale[1] = sex;
                       lowestmale[2] = subject;
                       lowestmale[3] = grade;
                   }
    
                }
                else
                {
                  if(highestfemale[3] == "" || (highestfemale[3] != "" && stoi(highestfemale[3]) < stoi(grade)))
                   {
                       //如果是第一次输入或者这一次输入的成绩比以往更高
                       highestfemale[0] = name;
                       highestfemale[1] = sex;
                       highestfemale[2] = subject;
                       highestfemale[3] = grade;
                   }
                }
            }
            if(highestfemale[0] != "")
               cout << highestfemale[0] << " " <<highestfemale[2] << endl;
            else
               cout << "Absent" << endl;
    
            if(lowestmale[0] != "")
               cout << lowestmale[0] << " " <<lowestmale[2] << endl;
            else
               cout << "Absent" << endl;
    
            if(lowestmale[0] != "" && highestfemale[0] != "")
               cout << stoi(highestfemale[3]) - stoi(lowestmale[3]) << endl;
            else
               cout << "NA" << endl;
        }
    }
    
    
    
     
     
  • 相关阅读:
    flask之视图
    android studio 配置阿里云镜像 加速
    mac idea phpstorm 提示 clear read-only status 解决办法
    如何给网站一键变黑?如哀悼日,一行css代码解决
    Android base64加密中文乱码问题解决记录
    微信Android app支付 重要记录,重要!!
    mysql 数据库拷贝innodb 操作注意事项,宝塔面板
    Linux 服务器使用shell脚本 实现 间隔N秒访问url
    echarts pie饼图块颜色设置
    Linux 服务器 node 节点满了引发的灾难,请定期清理node节点
  • 原文地址:https://www.cnblogs.com/0kk470/p/7623093.html
Copyright © 2011-2022 走看看