• 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 grade~F~-grade~M~. 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

     1 #include<iostream>
     2 #include<vector>
     3 #include<algorithm>
     4 using namespace std;
     5 struct node{
     6   char name[11], id[11];
     7   int score;
     8 };
     9 bool cmp(node a, node b){return a.score<b.score;}
    10 int main(){
    11   int n, i;
    12   cin>>n;
    13   vector<node> female, male;
    14   for(i=0; i<n; i++){
    15     node stu;
    16     char sex;
    17     scanf("%s %c %s %d", stu.name, &sex, stu.id, &stu.score);
    18     if(sex=='M') male.push_back(stu);
    19     else female.push_back(stu);
    20   }
    21   sort(male.begin(), male.end(), cmp);
    22   sort(female.begin(), female.end(), cmp);
    23   bool flag = true;
    24   if(female.size()==0) {cout<<"Absent
    "; flag=false;}
    25   else printf("%s %s
    ", female[female.size()-1].name, female[female.size()-1].id);
    26   if(male.size()==0) {cout<<"Absent
    "; flag=false;}
    27   else printf("%s %s
    ", male[0].name, male[0].id);
    28   if(flag) cout<<female[female.size()-1].score-male[0].score<<endl;
    29   else cout<<"NA"<<endl;
    30   return 0;
    31 }
    有疑惑或者更好的解决方法的朋友,可以联系我,大家一起探讨。qq:1546431565
  • 相关阅读:
    全链路压测(4):全链路压测的价值是什么?
    基于SVN的版本范围汇总
    一篇值得思考的职业教育之路!
    分享35个讨人喜欢的漂亮进度条UI设计
    转一篇难得的好文章CPU流水线的探秘之旅
    超棒的获奖动物摄影作品集
    解决web.py在SAE云中的Session使用问题
    2012年度最新免费web开发设计资源荟萃
    Endless icon: 每天都更新的图标集
    不容错过的超棒Javascript日期处理类库Moment.js
  • 原文地址:https://www.cnblogs.com/mr-stn/p/9163688.html
Copyright © 2020-2023  润新知