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. SpartanBrowser产品和安全特性简介

    v:* { } o:* { } w:* { } .shape { }p.MsoNormal,li.MsoNormal,div.MsoNormal { margin: 0cm; margin-botto ...

  2. OpenCV 轮廓检测

    使用OpenCV可以对图像的轮廓进行检测.这是之前用过的代码,挺简单的,回顾一下.主要要进行以下2步操作: 1.cvThreshold():对图像进行二值化处理 2.cvFindContours(): ...

  3. UML之包图

    包图是UML中用类似于文件夹的符号表示的模型元素的组合,系统中的每个元素都只能为一个包所有,一个包可嵌套在另一个包中,使用包图可将相关元素归入一个系统,一个包中包含附属包.图表或单个元素.简单的来说, ...

  4. 4.windows环境下如何安装memcached教程(转载+自己整理)

     Memcached 是一个开源免费高性能的分布式内存对象缓存系统,能够加快网站访问速度和减轻数据库压力,本文向大家介绍下windows环境下如何安装memcached.百度经验:jingyan. ...

  5. tomcat中的线程问题

    看这篇文章之前,请先阅读: how tomcat works 读书笔记 十一 StandWrapper 上 地址如下: http://blog.csdn.net/dlf123321/article/d ...

  6. ERP-非财务人员的财务培训教(一.一)------基本会计知识

    一.基本会计知识 第一节 会计是企业的语言 反映企业经济状况的两组会计语言词汇 四个层次的会计语言规则 财务会计报告的组成 会计语言要素 会计工作主要是把企业杂乱的会计数据归纳整理,加工编制成有用的财 ...

  7. Erlang cowboy routing 路由

    Erlang cowboy routing 路由 本文译自: http://ninenines.eu/docs/en/cowboy/1.0/guide/routing/ Routing 默认情况下,C ...

  8. 高通 android平台LCD驱动分析

    目前手机芯片厂家提供的源码里包含整个LCD驱动框架,一般厂家会定义一个xxx_fb.c的源文件,注册一个平台设备和平台驱动,在驱动的probe函数中来调用register_framebuffer(), ...

  9. HttpWebRequest类库注意事项以及常见问题

    ServicePoint: 提供HTTP连接的连接管理ServicePointManager: 管理ServicePoint 对象的集合 注意事项:1. 将http的request的keepAlive ...

  10. 四、删除 Delete

    文档目录 开始使用  初始化查询实例: LambdaToSql.SqlClient DB = new LambdaToSql.SqlClient(); 删除单个实体,通过Guid主键删除 var gu ...