返回列表 發帖
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. struct student
  4. {
  5.     string name;
  6.     int score;
  7. };
  8. bool compare(student a, student b)
  9. {
  10.     return a.score>b.score;
  11. }
  12. student st[4];
  13. int main()
  14. {
  15.     st[0].name="Bob";
  16.     st[1].name="Cindy";
  17.     st[2].name="Alice";
  18.     st[3].name="Mary";
  19.     st[0].score=70;
  20.     st[1].score=66;
  21.     st[2].score=77;
  22.     st[3].score=76;
  23.     for(student s: st)
  24.         cout<<s.name<<"\t"<<s.score<<" 分"<<endl;
  25.     sort(st, st+4, compare);
  26.     for(student s: st)
  27.         cout<<s.name<<"\t"<<s.score<<" 分"<<endl;
  28.     return 0;
  29. }
複製代碼
Ivy

TOP

返回列表