PAT1036:Boys vs Girls
1036. Boys vs Girls (25)
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的更多相关文章
- PAT1036. Boys vs Girls (25)
#include <iostream> #include <algorithm> #include <vector> using namespace std; st ...
- 1036 Boys vs Girls (25 分)
1036 Boys vs Girls (25 分) This time you are asked to tell the difference between the lowest grade of ...
- PAT 1036 Boys vs Girls[简单]
1036 Boys vs Girls (25 分) This time you are asked to tell the difference between the lowest grade of ...
- PAT 甲级 1036 Boys vs Girls (25 分)(简单题)
1036 Boys vs Girls (25 分) This time you are asked to tell the difference between the lowest grade ...
- PAT 1036 Boys vs Girls (25 分)
1036 Boys vs Girls (25 分) This time you are asked to tell the difference between the lowest grade ...
- 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 ...
- 1036 Boys vs Girls (25分)(水)
1036 Boys vs Girls (25分) This time you are asked to tell the difference between the lowest grade o ...
- PAT甲级:1036 Boys vs Girls (25分)
PAT甲级:1036 Boys vs Girls (25分) 题干 This time you are asked to tell the difference between the lowest ...
- 1036. Boys vs Girls (25)
#include <stdio.h>#include <string.h>int main(){ int n,i; while(scanf("%d",&am ...
随机推荐
- CentOS 6.X启动流程
CentOS 6.X启动流程 /boot分区 启动引导程序是默认可以识别boot分区的.因此在系统还无法加载硬盘的时候,boot分区是可以识别的! initramfs内存文件系统 CentOS 6.x ...
- Android For JNI(一)——JNI的概念以及C语言开发工具dev-c++,编写你的第一个C语言程序,使用C启动JAVA程序
Android For JNI(一)--JNI的概念以及C语言开发工具dev-c++,编写你的第一个C语言程序 当你的Android之旅一步步的深入的时候,你其实会发现,很多东西都必须去和framew ...
- /dev、/sys/dev 和/sys/devices 和udev的关系
/dev,设备文件存储目录,应用程序通过对这些文件的读写和控制,可以访问实际的设备: /sys/devices目录,按照设备挂接的总线类型,组织成层次结构,保存了系统所有的设备:是文件系统管理设备的最 ...
- Android下Json数据解析
如从网络获取JSON 则需要创建一个工具类,该类返回一个字符串为JSON文本 package com.example.jsonapp; import java.io.InputStreamReader ...
- linux下32位汇编调用规则
传递给系统调用的参数必须安装参数顺序一次放到寄存器中,当系统调用完成后,返回值放在eax中: 当系统调用参数<=5个时: eax中存放系统调用的功能号,传递给系统调用的参数顺序依次放到寄存器:e ...
- 循环赛日程编排c代码
#include <stdio.h> int m,s,n; int i,j; int a[100][100]; int sf(int n) { if(n%2!=0) printf(&quo ...
- rails应用ajax之二:使用rails自身支持
考虑另一种情况: 1. 页面上半部分显示当前的所有用户,页面下半部分是输入新用户的界面: 2. 每当输入新用户时,页面上半部分会动态更新新加用户的内容: 我们还是用ajax实现,不过这次用rails内 ...
- sxoi爆炸祭
好吧,纯粹是去玩玩的,我这么一个弱省的蒟蒻,进队纯粹是开玩笑.... Day0 去五中试机,感觉电脑手感不错,打了半个线段树的板子才发现试机要在自己的电脑上试,然后我无奈的搬东西(从26号搬到2号), ...
- Android布局优化:include 、merge、ViewStub的详细总结
版权声明:本文出自汪磊的博客,未经作者允许禁止转载. 本篇博客主要是对上篇博客的补充Android性能优化之UI渲染性能优化, 没有什么新东西,觉得应该是都掌握的玩意,写出来也只是自己做个小小的总结. ...
- Windows平台安装及配置Hadoop(不借助cygwin)
由于项目需要,我在VMware上装了几个虚拟机Windows server 2012 R2,并要搭建Hadoop集群.刚刚入门hadoop,一头雾水,然后开始搜各种教程,首先是选用cygwin进行安装 ...