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. Logistic Regression求解classification问题

    classification问题和regression问题类似,区别在于y值是一个离散值,例如binary classification,y值只取0或1. 方法来自Andrew Ng的Machine ...

  2. AP INVOICES IMPORT API(NOT request)

    PROCEDURE process_cux_to_ap(x_return_status OUT NOCOPY VARCHAR2, x_msg_count OUT NOCOPY NUMBER, x_ms ...

  3. FFMPEG结构体分析:AVFrame

    注:写了一系列的结构体的分析的文章,在这里列一个列表: FFMPEG结构体分析:AVFrameFFMPEG结构体分析:AVFormatContextFFMPEG结构体分析:AVCodecContext ...

  4. 安卓Eclipse开发者的福音

    我们知道,谷歌已经放弃对Eclipse(ADT)的维护更新了,现在官网上也找不到ADT的下载链接了,我们大多数同学仍在使用的ADT版本可能已经很老了,估计大多数的SDK版本只到4.4,而,在尝试升级以 ...

  5. 二分算法C实现

    #include <stdio.h> #include <stdlib.h> #define NR(x) (sizeof(x)/sizeof(x[0])) int Binary ...

  6. android 高斯模糊实现

    高斯模糊 高斯模糊就是将指定像素变换为其与周边像素加权平均后的值,权重就是高斯分布函数计算出来的值. 一种实现 点击打开链接<-这里是一片关于高斯模糊算法的介绍,我们需要首先根据高斯分布函数计算 ...

  7. PS 图像调整算法——饱和度调整

    算法参考自 阿发伯 的博客. http://blog.csdn.net/maozefa 饱和度调整 图像的饱和度调整有很多方法,最简单的就是判断每个象素的R.G.B值是否大于或小于128,大于加上调整 ...

  8. C语言算法--统计字符串中单词的个数

    #include <stdio.h> #include <string.h> #include <stdlib.h> int main(void) { int le ...

  9. 2018国赛 - Writeup(待补充)

    10.0.0.55 Writeup Web 0x01 easyweb 解题思路 题目很脑洞 用户名admin 密码123456进去可得到flag(密码现在换了) 解题脚本 无 Reverse 0x02 ...

  10. 学习一下DOM中的cloneNode()与cloneNode(true)的基础知识

    带你去熟悉HTML dom中当然cloneNode()与cloneNode(true)之间区别 code <!DOCTYPE html> <html> <head> ...