PAT 1036. Boys vs Girls (25)
2014-02-27 18:37
483 查看
1036. Boys vs Girls (25)
时间限制400 ms
内存限制
32000 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
提交代码
/* 满分 与 0分 的差别:scanf(" %c",&a); 输入字符前必须要加个空格!!!!! */ #include<stdio.h> #include<string.h> #include<algorithm> using namespace std; const int MAX=100; int cnt1,cnt2; struct E{ char name[20]; char sex; char no[20]; int grade; }; bool cmp1(E a,E b) { return a.grade<b.grade; } bool cmp2(E c,E d) { return c.grade>d.grade; } int main() { int n,i; //freopen("G:\\in.txt","r",stdin); //freopen("G:\\our.txt","w",stdout); while(scanf("%d",&n)!=EOF){ cnt1=0;cnt2=0; E boy[MAX],girl[MAX]; char nameT[20],sexT,noT[20]; int gradeT; for(i=0;i<n;i++){ scanf("%s %c%s%d",nameT,&sexT,noT,&gradeT);//输入字符前必须要加个空格!!!!! if(sexT=='M'){ strcpy(boy[cnt1].name,nameT); boy[cnt1].sex=sexT; strcpy(boy[cnt1].no,noT); boy[cnt1].grade=gradeT; cnt1++; }else{ strcpy(girl[cnt2].name,nameT); girl[cnt2].sex=sexT; strcpy(girl[cnt2].no,noT); girl[cnt2].grade=gradeT; cnt2++; } } if(cnt2!=0){ //输出成绩最高的女生 sort(girl,girl+cnt2,cmp2); printf("%s %s\n",girl[0].name,girl[0].no); }else printf("Absent\n"); if(cnt1!=0){ //输出成绩最低的男生 sort(boy,boy+cnt1,cmp1); printf("%s %s\n",boy[0].name,boy[0].no); }else{ printf("Absent\n"); } if(cnt1!=0&&cnt2!=0) printf("%d\n",girl[0].grade-boy[0].grade); else printf("NA\n"); } return 0; }
相关文章推荐
- 【PAT甲级】1036. Boys vs Girls (25)
- 浙江大学PAT_甲级_1036. Boys vs Girls (25)
- PAT 1036. Boys vs Girls (25)
- 【C++】PAT(advanced level)1036. Boys vs Girls (25)
- PAT (Advanced) 1036. Boys vs Girls (25)
- PAT 1036. Boys vs Girls (25)
- 【PAT甲级】1036. Boys vs Girls (25)——JAVA实现
- PAT (Advanced Level)1036. Boys vs Girls (25)
- 1036. Boys vs Girls (25)-PAT甲级真题
- 1036. Boys vs Girls (25)【水题】——PAT (Advanced Level) Practise
- PAT (Advanced Level) 1036. Boys vs Girls (25)
- PAT甲题题解-1036. Boys vs Girls (25)-找最大最小,大水题
- PAT 1036. Boys vs Girls (25)
- PAT (Advanced Level) 1036. Boys vs Girls (25) 解题报告
- PAT (Advanced Level) Practise 1036 Boys vs Girls (25)
- pat 1036. Boys vs Girls (25)
- PAT甲级真题及训练集(10)--1036. Boys vs Girls (25)
- PAT (Advanced Level) 1036. Boys vs Girls (25) 结构体排序
- PAT-A-1036. Boys vs Girls (25)
- PAT甲级.1036. Boys vs Girls (25)