PAT(甲级)1036
来源:互联网 发布:mysql btree索引原理 编辑:程序博客网 时间:2024/05/17 08:40
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 <cstdio>#include <cstring>#include <algorithm>#define SIZE 10007using namespace std;struct Student{char name[16];char ID[16];int grade;};Student Boys[SIZE];Student Girls[SIZE];bool cmp(const Student &s1,const Student &s2){return s1.grade < s2.grade;}int main(){int nums_boys,nums_girls,N;int i;char name[16],ch;nums_boys=nums_girls=0;scanf("%d",&N);//Student *Boys = new Student[N];//Student *Girls = new Student[N];for(i=0;i<N;i++){scanf("%s %c ",name,&ch);if(ch == 'M'){strcpy(Boys[nums_boys].name,name);scanf("%s %d",Boys[nums_boys].ID,&Boys[nums_boys].grade);nums_boys++;}else{strcpy(Girls[nums_girls].name,name);scanf("%s %d",Girls[nums_girls].ID,&Girls[nums_girls].grade);nums_girls++;}}bool flag1,flag2;flag1=flag2=true;if(nums_boys){sort(Boys,Boys+nums_boys,cmp);}else flag1= false;if(nums_girls){sort(Girls,Girls+nums_girls,cmp);}else flag2=false;if(flag1&&flag2){printf("%s %s\n%s %s\n%d",Girls[nums_girls-1].name,Girls[nums_girls-1].ID,Boys[0].name,Boys[0].ID,Girls[nums_girls-1].grade-Boys[0].grade);}else{if(!flag2) printf("Absent\n");else printf("%s %s\n",Girls[nums_girls-1].name,Girls[nums_girls-1].ID);if(!flag1) printf("Absent\n");else printf("%s %s\n",Boys[0].name,Boys[0].ID);printf("NA\n");}return 0;}
- PAT(甲级)1036
- PAT甲级1036
- PAT甲级 1036 -- 没有注释
- PAT 甲级
- PAT甲级 A1025.PAT RANKING
- PAT 甲级 1025 PAT Ranking
- PAT(甲级)1003
- PAT(甲级)1004
- PAT(甲级)1005
- PAT(甲级)1006
- PAT(甲级)1007
- PAT(甲级)1008
- PAT(甲级)1009
- PAT(甲级)1010
- PAT(甲级)1011
- PAT(甲级)1012
- PAT(甲级)1013
- PAT(甲级)1014
- Vmware虚拟机下三种网络模式配置
- 3.3.3 Differ对象
- HDU 1181 DFS
- PAT(甲级)1035
- 静态成员函数的作用与静态数据成员的初始化
- PAT(甲级)1036
- LeetCode 19_Remove Nth Node From End of List
- 我读过的好书
- phpt文件说明,php官方自动测试方法,run-test.php命令用法
- 工具提示
- PAT(甲级)1037
- HDU - 1024 Max Sum Plus Plus(DP + 滚动数组)
- imread
- String,StringBuffer,StringBuild的区别