zoukankan      html  css  js  c++  java
  • 1004. 成绩排名 (20)

    读入n名学生的姓名、学号、成绩,分别输出成绩最高和成绩最低学生的姓名和学号。

    输入格式:每个测试输入包含1个测试用例,格式为

      第1行:正整数n
      第2行:第1个学生的姓名 学号 成绩
      第3行:第2个学生的姓名 学号 成绩
      ... ... ...
      第n+1行:第n个学生的姓名 学号 成绩
    

    其中姓名和学号均为不超过10个字符的字符串,成绩为0到100之间的一个整数,这里保证在一组测试用例中没有两个学生的成绩是相同的。

    输出格式:对每个测试用例输出2行,第1行是成绩最高学生的姓名和学号,第2行是成绩最低学生的姓名和学号,字符串间有1空格。

    输入样例:

    3
    Joe Math990112 89
    Mike CS991301 100
    Mary EE990830 95
    

    输出样例:

    Mike CS991301
    Joe Math990112

    思路:typedef结构体,简单基础排序题目
    #include<iostream>
    #include<algorithm>
     
     using namespace std;
     
     typedef struct
     {
         string stu_Name;
         string stu_Id;
         int    stu_Score;
         
     }stu;
     
     int main()
     {
         int n;
         cin>>n;
         stu max_Stu,min_Stu;
         max_Stu.stu_Score = -1;
         min_Stu.stu_Score = 101;
         for(int i=0; i<n; i++)
         {
             stu in;
            cin>>in.stu_Name;
            cin>>in.stu_Id;
            cin>>in.stu_Score;
             if(in.stu_Score > max_Stu.stu_Score)
             {
                 max_Stu.stu_Name = in.stu_Name;
                 max_Stu.stu_Id = in.stu_Id;
                 max_Stu.stu_Score = in.stu_Score;
            }
             if(in.stu_Score < min_Stu.stu_Score)
            {
                min_Stu.stu_Name = in.stu_Name;
                min_Stu.stu_Id = in.stu_Id;
                min_Stu.stu_Score = in.stu_Score;
            }
    //        printf("-------------------inScore=:%d,minscore=:%d,maxScore=:%d
    ",in.stu_Score,min_Stu.stu_Score,max_Stu.stu_Score);
        }
        cout<<max_Stu.stu_Name<<" "<<max_Stu.stu_Id<<endl;
        cout<<min_Stu.stu_Name<<" "<<min_Stu.stu_Id<<endl;
         
         return 0;
         
      } 
  • 相关阅读:
    6 网络爬虫引发的问题及Robots协议
    WEB测试方法总结-笔记(转)
    最全的Http协议、get和post请求的整理
    random()函数的应用---面试
    求两个列表的交集、差集、并集---面试
    python中函数参数传递--引用传递(面试)
    linux重定向命令>和>>---面试
    正则表达式re.findall和re.search的使用---面试
    关于可迭代对象的详解
    sorted()函数排序的灵活运用---面试
  • 原文地址:https://www.cnblogs.com/valar/p/6147026.html
Copyright © 2011-2022 走看看