1. 程式人生 > >1004 成績排名 未解決的問題

1004 成績排名 未解決的問題

include nbsp card int ret i++ tex lis 輸入格式

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 成績排名 未解決的問題