1036. Boys vs Girls
来源:互联网 发布:微信扫码登录源码 编辑:程序博客网 时间:2024/06/05 07: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
//1036. Boys vs Girls//和1083一个道理 #include<iostream>#include<string>#include<vector>#include<algorithm>using namespace std;struct Student{string name;char s;string id;int grade;};bool cmp(const Student& s1, const Student& s2){return s1.grade > s2.grade;}vector<Student> students(110);int main(){int stuNum;cin>>stuNum;for (int i = 0; i < stuNum; i++) cin>>students[i].name>>students[i].s>>students[i].id>>students[i].grade; sort(students.begin(), students.end(), cmp); int male_grade, female_grade; bool flag1 = true, flag2 = true; for (int i = 0; i < students.size(); i++) { if (students[i].s == 'F') { cout<<students[i].name<<" "<<students[i].id<<endl; flag1 = false; female_grade = students[i].grade; break; } } if (flag1) cout << "Absent"<<endl; for (int i = students.size() - 1; i >= 0 ; i--) { if (students[i].s == 'M') { cout<<students[i].name<<" "<<students[i].id<<endl; flag2 = false; male_grade = students[i].grade; break; } } if (flag2) cout << "Absent"<<endl; if(!flag1 && !flag2) cout<<female_grade-male_grade<<endl; else cout<<"NA"<<endl;return 0;}
- 1036. Boys vs Girls
- 1036. Boys vs Girls
- 1036. Boys vs Girls
- 1036.Boys vs Girls
- 1036. Boys vs Girls
- 1036. Boys vs Girls
- 1036. Boys vs Girls
- 1036. Boys vs Girls
- 1036. Boys vs Girls
- 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)
- zoj 3430 Detect the Virus 【AC自动机】【坑死。。。】
- hiho1014: Trie树
- Qt5.5在ubuntu下解决 GL/gl.h: No such file or directory 与 cannot find -lGL
- NLTK学习一
- UVa 620 Cellular Structure
- 1036. Boys vs Girls
- 带层级关系的递归遍历目录内容
- C++Primer第五版 11.3.5节练习
- 插件开发技术说明(17)---应用CRUD开发模式范例
- Android Socket 使用(客户端和服务端)
- iOS开发中的字典转模型应用
- debian 源
- 02-线性结构1 一元多项式的乘法与加法运算
- 伪任意地址HOOK类