1004 成績排名 未解決的問題

來源:互聯網
上載者:User

標籤:cout   list   card   ret   學生   info   swa   測試案例   class   

1004 成績排名 (20 分)

讀入 n(>0)名學生的姓名、學號、成績,分別輸出成績最高和成績最低學生的姓名和學號。

輸入格式:

每個測試輸入包含 1 個測試案例,格式為

第 1 行:正整數 n第 2 行:第 1 個學生的姓名 學號 成績第 3 行:第 2 個學生的姓名 學號 成績  ... ... ...第 n+1 行:第 n 個學生的姓名 學號 成績
輸入範例:
3Joe Math990112 89Mike CS991301 100Mary EE990830 95
輸出範例:
Mike CS991301Joe 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 成績排名 未解決的問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.