当前位置: 移动技术网 > IT编程>开发语言>C/C++ > 1004 成绩排名 未解决的问题

1004 成绩排名 未解决的问题

2018年09月30日  | 移动技术网IT编程  | 我要评论

10张就算是天使也会想歪的图片,日照海域再现赤潮,文字图片大全

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*****************/

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网