返回列表 發帖
  1. #include<bits/stdc++.h>
  2. using namespace std;

  3. struct student{
  4.     string name;
  5.     int score;
  6. };
  7. bool compare(student a,student b){
  8.     return a.score>b.score;
  9. }
  10. student st[4];
  11. void show(){
  12.    for(student s:st){
  13.         cout<<s.name<<" "<<s.score<<"分"<<endl;
  14.    }
  15.    cout<<endl;
  16. }
  17. int main()
  18. {
  19.     cin.tie(0);
  20.     cin.sync_with_stdio(0);
  21.     st[0].name="Bob";
  22.     st[0].score=70;
  23.     st[1].name="Cindy";
  24.     st[1].score=66;
  25.     st[2].name="Alice";
  26.     st[2].score=77;
  27.     st[3].name="Mary";
  28.     st[3].score=76;
  29.     show();
  30.     sort(st,st+4,compare);
  31.     show();
  32.     return 0;
  33. }
複製代碼
hahahahahahahaha

TOP

返回列表