码迷,mamicode.com
首页 > 其他好文 > 详细

1004 成绩排名 未解决的问题

时间:2018-09-29 22:04:33      阅读:115      评论:0      收藏:0      [点我收藏+]

标签:cout   list   card   ret   学生   info   swa   测试用例   class   

1004 成绩排名 (20 分)

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

输入格式:

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

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

输入样例:

3
Joe Math990112 89
Mike CS991301 100
Mary EE990830 95

输出样例:

Mike CS991301
Joe Math990112


 1 #include "stdafx.h"
 2 #include <algorithm>
 3 #include <iostream>
 4 
 5 using namespace std;
 6   struct student {
 7     char name[10];
 8     char num[10];
 9     int score;
10 }stu[10010];
11 bool com(student a, student b)
12 {
13     return a.score < b.score;
14 
15 }
16 void swap(student a, student b) {
17     student c;
18     c = a;
19     a = b;
20     b = c; 
21 }
22 int main()
23 {
24     int n;
25     cin >> n;
26     for (int i = 0; i < n; i++) {
27         cin >> stu[i].name >> stu[i].num >> stu[i].score;
28     }
29     for (int i = 0; i <= n; i++) {
30         if (com(stu[i], stu[i + 1]))
31             swap(stu[i], stu[i + 1]);
32     }
33     for (int i = n; i>=0; i--) {
34         if(i==n-1)
35         cout << stu[i].name <<" "<< stu[i].num<<"\n";
36         if (i == 0)
37             cout << stu[i].name<<" " << stu[i].num ;
38         
39     }
40     
41 
42     return 0;
43 }

技术分享图片

/******* 为什么会打印出y*****************/

 

1004 成绩排名 未解决的问题

标签:cout   list   card   ret   学生   info   swa   测试用例   class   

原文地址:https://www.cnblogs.com/mimogod/p/9726809.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!