1036. Boys vs Girls (25)
来源:互联网 发布:法规的软件 编辑:程序博客网 时间:2024/05/22 10:31
This time you are asked to tell the difference between the lowest grade of all the male students and the highest grade ofall 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 <algorithm>#include <vector>using namespace std;/* run this program using the console pauser or add your own getch, system("pause") or input loop */struct student{char name[12],id[12];char gender;int grade;};int N;vector<student> vfemale;vector<student> vmale;student maxfemale,minmale;int main(int argc, char** argv) {scanf("%d",&N);maxfemale.grade=-1;minmale.grade=101;for(int i=0; i<N; i++){student tmp;scanf("%s %c %s %d",tmp.name,&tmp.gender,tmp.id,&tmp.grade);if(tmp.gender=='F'){if(tmp.grade>maxfemale.grade){maxfemale=tmp;}}else{if(tmp.grade<minmale.grade){minmale=tmp;}}}if(maxfemale.grade==-1){printf("Absent\n");}else{printf("%s %s\n",maxfemale.name,maxfemale.id);}if(minmale.grade==101){printf("Absent\n");}else{printf("%s %s\n",minmale.name,minmale.id);}if(maxfemale.grade==-1 || minmale.grade==101){printf("NA\n");}else{printf("%d\n",abs(maxfemale.grade-minmale.grade));}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)
- 程序员必备技能
- 【java】finalize()函数详解
- 从零开始学Android之 AutoCompleteView 动态匹配输入的内容(像搜索引擎上的匹配)
- VS问题之端口正在使用
- 打印数组的全排列
- 1036. Boys vs Girls (25)
- 什么是程序员
- oracle表分区详解
- 获取数据库中表名
- Leetcode: Palindrome Partitioning
- python 爬虫3 新浪微博 爬虫 实战
- leetcode 227: Basic Calculator II
- HDU 1231 最大连续子序列(最大连续子段和)
- 【bzoj3505】【CQOI2014】【数三角形】【组合数学】