PAT-A-1036. Boys vs Girls (25)
来源:互联网 发布:双向数据绑定的实现 编辑:程序博客网 时间:2024/05/22 06:10
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:
3Joe M Math990112 89Mike M CS991301 100Mary F EE990830 95Sample Output 1:
Mary EE990830Joe Math9901126Sample Input 2:
1Jean M AA980920 60Sample Output 2:
AbsentJean AA980920NA
#include<iostream>#include<cstdio>#include<string.h>#include<algorithm>using namespace std;struct student{ char name[11]; char gender; char id[11]; int grade;};int main(){ int n; struct student male, female; int fm = 0, ff = 0; cin >> n; char name[11]; char gender; int grade; char id[11]; int minm = 101, maxf = -1; for (int i = 0; i < n; i++) { cin >> name >> gender >> id >> grade; if (gender == 'M') { if (grade<minm) { minm = grade; fm = 1; male.gender = gender; //strcpy_s(male.name ,name); //strcpy_s(male.id, id); strcpy(male.name, name); strcpy(male.id, id); male.grade = grade; } } else { if (grade>maxf) { maxf = grade; ff = 1; female.gender = gender; //strcpy_s(female.name, name); //strcpy_s(female.id, id); strcpy(female.name, name); strcpy(female.id, id); female.grade = grade; } } } int falg = 1; if (ff == 0) { cout << "Absent" << endl; falg = 0; } else { cout << female.name << " " << female.id << endl; } if (fm == 0) { cout << "Absent" << endl; falg = 0; } else { cout << male.name << " " << male.id << endl; } if (falg) cout << maxf - minm << endl; else cout << "NA" << endl; system("pause"); return 0;}
- PAT A 1036. Boys vs Girls (25)
- PAT A 1036. Boys vs Girls (25)
- PAT-A 1036. Boys vs Girls (25)
- PAT-A-1036. Boys vs Girls (25)
- PAT-A 1036. Boys vs Girls
- 1036. Boys vs Girls (25)-PAT
- 【PAT】1036. Boys vs Girls (25)
- PAT 1036. Boys vs Girls (25)
- PAT 1036. Boys vs Girls (25)
- pat 1036. Boys vs Girls (25)
- PAT 1036. Boys vs Girls (25)
- PAT甲级.1036. Boys vs Girls (25)
- 1036. Boys vs Girls (25) PAT 甲级
- 【PAT甲级】1036. Boys vs Girls (25)
- PAT甲级1036. Boys vs Girls (25)
- PAT 甲级 1036. Boys vs Girls (25)
- PAT甲级 1036. Boys vs Girls (25)
- PAT刷题:1036. Boys vs Girls (25)
- VFS笔记
- RESTful API 设计指南
- ANTLR4在windows上的安装(java版)
- html.随笔
- JetBrains PhpStorm 2017.1.4 x64+PHPWAMP+Xdebug环境配置以及断点调试
- PAT-A-1036. Boys vs Girls (25)
- 关于xshell无法连接虚拟机中linux
- Xcode 9 俩个你必须知道的新功能
- 依赖注入和控制反转
- 洛谷Oj-约数研究-数学
- STM32F429之IO操作
- Chapter 1 Section 1.4 Vocabulary
- mysql大数据量之limit优化
- swoole HTTP服务器中异步MySQL