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. hadoop学习视频

    杨尚川的视频 http://www.tudou.com/plcover/EvJCo2zl9hQ/ 酷6视频 http://v.ku6.com/show/8PkgqGcarHKndyP3rl_pUw.. ...

  2. windows下追踪路由

    追踪路由 tracert   目标ip/域名 测试两个ip是否畅通 ping    目标ip 在windows查看ip情况 ipconfig linux/unix下查看ip情况的使用 ifconfig

  3. Developing RIA Web Applications with Oracle ADF

      Developing RIA Web Applications with Oracle ADF Purpose This tutorial shows you how to build a ric ...

  4. hbase 集群管理脚本

    #!/bin/bash # Show all running Java processes on region servers. Must run on master using HBase owne ...

  5. 利用PreLoader实现一个平视显示(HUD)效果(可以运用到加载等待效果),并进行简单的讲解

    什么是PreLoader? PreLoader是由Volodymyr Kurbatov设计的一个很有意思的HUD(平视显示效果(Head Up Display)),通过运动污点和固定污点之间的粘黏动画 ...

  6. OpenCV——PS 图层混合算法 (四)

    具体的算法原理可以参考 PS图层混合算法之四(亮光, 点光, 线性光, 实色混合) // PS_Algorithm.h #ifndef PS_ALGORITHM_H_INCLUDED #define ...

  7. LeetCode(47)-Reverse Bits

    题目: Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented ...

  8. ubuntu12.04:Mysql数据库:手动安装

    首先到mysql的下载中心上下载最新的tar.gz包: 1.在浏览器中输入http://www.mysql.com/downloads/ 进入mysql的下载中心,在这里有使用mysql开发的一些工具 ...

  9. WebService学习--(一)webservice相关概念

    一.序言 大家或多或少都听过 WebService(Web服务),有一段时间很多计算机期刊.书籍和网站都大肆的提及和宣传WebService技术,其中不乏很多吹嘘和做广告的成 分.但是不得不承认的是W ...

  10. pyqt5 动画在QThread线程中无法运行问题

    自己做了一个tcp工具,在学习动画的时候踩了坑,需求是根据上线变绿色,离线变灰色,如果连接断开了,则变为灰色 问题现象: 可以看到点击"连接","离线"的时候动 ...