1036. Boys vs Girls (25)
来源:互联网 发布:asp.net php学那个好 编辑:程序博客网 时间:2024/06/02 00:57
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 <stdio.h> #include <stdlib.h> typedef struct node{char name[15];char gender[2];char id[15];int grade;struct node *next;}NODE;int main() { NODE *MaleHead,*FemaleHead;NODE *MaleP,*FemaleP;NODE *t;int N,i;MaleHead = (NODE*)malloc(sizeof(NODE));FemaleHead = (NODE*)malloc(sizeof(NODE));MaleHead->next = NULL;FemaleHead->next = NULL;MaleP = MaleHead;FemaleP = FemaleHead;scanf("%d",&N);for(i=0;i<N;i++){t = (NODE*)malloc(sizeof(NODE));t->next = NULL;scanf("%s%s%s%d",t->name,t->gender,t->id,&t->grade);if(t->gender[0] == 'M'){MaleP->next = t;MaleP = t;}else{FemaleP->next = t;FemaleP = t;}}FemaleP = FemaleHead->next;t = FemaleP;while(t!=NULL){if(t->grade > FemaleP->grade){FemaleP = t;}t = t->next;}MaleP = MaleHead->next;t = MaleP;while(t!=NULL){if(t->grade < MaleP->grade){MaleP = t;}t = t->next;}if( MaleP!=NULL && FemaleP!=NULL){printf("%s %s\n",FemaleP->name,FemaleP->id);printf("%s %s\n",MaleP->name,MaleP->id);printf("%d\n",FemaleP->grade - MaleP->grade);}else{if(FemaleP!=NULL){printf("%s %s\n",FemaleP->name,FemaleP->id);}else{printf("Absent\n");}if(MaleP!=NULL){printf("%s %s\n",MaleP->name,MaleP->id);}else{printf("Absent\n");}printf("NA\n");}//system("pause"); return 0; }
- 1036. Boys vs Girls (25)
- 1036. Boys vs Girls (25)
- 1036. Boys vs Girls (25)
- 1036. Boys vs Girls (25)
- 1036. Boys vs Girls (25)
- 1036. Boys vs Girls (25)
- 1036. Boys vs Girls (25)
- 1036. Boys vs Girls (25)
- 1036. Boys vs Girls (25)
- 1036. Boys vs Girls (25)
- 1036. Boys vs Girls (25)
- 1036. Boys vs Girls (25)
- 1036. Boys vs Girls (25)
- 1036. Boys vs Girls (25)
- 1036. Boys vs Girls (25)
- 1036. Boys vs Girls (25)
- 1036. Boys vs Girls (25)
- 1036. Boys vs Girls (25)
- [CSU 1804 有向无环图] DP+拓扑排序
- Android databinding笔记
- 红黑树和AVL树的效率对比
- 无向图的深度优先生成森
- Request对象的主要方法:
- 1036. Boys vs Girls (25)
- mysql千万级数据表结构修改
- synchronized 详解
- eclipse上传代码到gitbub
- 1. JMeter 3.0 环境搭建
- 从机器学习谈起
- 实现Socket通信
- Codeforces Round #360 A 简单模拟
- Win10下安装Win7(新买固态硬盘)