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();
vector<string> highestfemale();
string name,sex,subject,grade;
for(int i = ; i < N;i++)
{
cin >> name >> sex >> subject >> grade;
if(sex == "M")
{
if(lowestmale[] == "" || (lowestmale[] != "" && stoi(lowestmale[]) > stoi(grade)))
{
//如果是第一次输入或者这一次输入的成绩比以往更低
lowestmale[] = name;
lowestmale[] = sex;
lowestmale[] = subject;
lowestmale[] = grade;
} }
else
{
if(highestfemale[] == "" || (highestfemale[] != "" && stoi(highestfemale[]) < stoi(grade)))
{
//如果是第一次输入或者这一次输入的成绩比以往更高
highestfemale[] = name;
highestfemale[] = sex;
highestfemale[] = subject;
highestfemale[] = grade;
}
}
}
if(highestfemale[] != "")
cout << highestfemale[] << " " <<highestfemale[] << endl;
else
cout << "Absent" << endl; if(lowestmale[] != "")
cout << lowestmale[] << " " <<lowestmale[] << endl;
else
cout << "Absent" << endl; if(lowestmale[] != "" && highestfemale[] != "")
cout << stoi(highestfemale[]) - stoi(lowestmale[]) << endl;
else
cout << "NA" << endl;
}
}

 
 

PAT1036:Boys vs Girls的更多相关文章

  1. PAT1036. Boys vs Girls (25)

    #include <iostream> #include <algorithm> #include <vector> using namespace std; st ...

  2. 1036 Boys vs Girls (25 分)

    1036 Boys vs Girls (25 分) This time you are asked to tell the difference between the lowest grade of ...

  3. PAT 1036 Boys vs Girls[简单]

    1036 Boys vs Girls (25 分) This time you are asked to tell the difference between the lowest grade of ...

  4. PAT 甲级 1036 Boys vs Girls (25 分)(简单题)

    1036 Boys vs Girls (25 分)   This time you are asked to tell the difference between the lowest grade ...

  5. PAT 1036 Boys vs Girls (25 分)

    1036 Boys vs Girls (25 分)   This time you are asked to tell the difference between the lowest grade ...

  6. PAT甲级——1036 Boys vs Girls

    1036 Boys vs Girls This time you are asked to tell the difference between the lowest grade of all th ...

  7. 1036 Boys vs Girls (25分)(水)

    1036 Boys vs Girls (25分)   This time you are asked to tell the difference between the lowest grade o ...

  8. PAT甲级:1036 Boys vs Girls (25分)

    PAT甲级:1036 Boys vs Girls (25分) 题干 This time you are asked to tell the difference between the lowest ...

  9. 1036. Boys vs Girls (25)

    #include <stdio.h>#include <string.h>int main(){ int n,i; while(scanf("%d",&am ...

随机推荐

  1. zookeeper+kafka集群安装之二

    zookeeper+kafka集群安装之二 此为上一篇文章的续篇, kafka安装需要依赖zookeeper, 本文与上一篇文章都是真正分布式安装配置, 可以直接用于生产环境. zookeeper安装 ...

  2. FFMPEG结构体分析:AVCodecContext

    注:写了一系列的结构体的分析的文章,在这里列一个列表: FFMPEG结构体分析:AVFrame FFMPEG结构体分析:AVFormatContext FFMPEG结构体分析:AVCodecConte ...

  3. 恶补web之八:jQuery(3)

    jquery和其他js框架.jQuery使用$作为jQuery的简写,但是还有很多js框架,比如: MooTools,Backbone,Sammy,Cappuccino,Knockout,JavaSc ...

  4. shc/unshc加/解密shell脚本

    一.加密软件shcshc是linux的一款加密脚本的插件东西比较安全我们可以利用wget将文件放在root目录下也可以通过sftp放在root目录也可以直接利用cd命令选择目录一切随意shc官网:ht ...

  5. ASP.NET Provider模式应用之SqlMembershipProvider类的剖析

    太多了,先给个流程图吧 Provider模式就是GOF中的两种设计模式的应用:策略模式和工厂模式,在程序中使用好这个模型能够解除模块与模块之间的耦合甚至是DIP,同时,不管是ASP.NET MVC还是 ...

  6. 深入了解Map

    联系 Java中的Map类似于OC的Dictionary,都是一个个键值对组成,一键对应一值.我在之前的文章中讲解过Set,其实在JAVA底层Set依赖的也是Map,那我们都知道,Set是单列的(只有 ...

  7. Eclipse配置SpringBoot

    从这一博客开始学习SpringBoot,今天学习Eclipse配置SpringBoot.Eclipse导入SpringBoot有两种方式,一种是在线一个是离线方式. 一.在线安装 点击Eclipse中 ...

  8. HashMap实现原理及源码分析(JDK1.7)

    转载:https://www.cnblogs.com/chengxiao/p/6059914.html 哈希表(hash table)也叫散列表,是一种非常重要的数据结构,应用场景及其丰富,许多缓存技 ...

  9. ORACLE分页SQL语句(转载)

    1.根据ROWID来分select * from t_xiaoxi where rowid in(select rid from (select rownum rn,rid from(select r ...

  10. Java Selenium 定位元素 实现的一个注册功能

    import java.util.List; import java.util.concurrent.TimeUnit; import org.openqa.selenium.Alert; impor ...