返回列表 發帖
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define int ll
  5. #define FOR(i,a,b) for(int i=a;i<b;i++)
  6. #define REP(i,n) FOR(i,0,n)
  7. #define REP1(i,n) FOR(i,1,(n)+1)
  8. #define RREP(i,n) for(int i=(n)-1;i>=0;i--)
  9. #define f first
  10. #define s second
  11. #define pb push_back
  12. #define ALL(x) x.begin(),x.end()
  13. #define SZ(x) (int)(x.size())
  14. #define SQ(x) (x)*(x)
  15. #define pii pair<int,int>
  16. #define Graph vector<vector<int>>
  17. #define IOS() cin.sync_with_stdio(0),cin.tie(0),cout.tie(0)
  18. const ll inf=(1ll<<63)-1;
  19. const int maxn=1e5+5;
  20. const ll mod=1e9+7;
  21. struct P {
  22.     string na;
  23.     int sc;
  24. };
  25. vector<P> v;
  26. bool operator<(P a,P b) {
  27.     return a.sc<b.sc;
  28. }
  29. signed main()
  30. {
  31.     IOS();
  32.     v.pb({"Bob",70});
  33.     v.pb({"Cindy",66});
  34.     v.pb({"Alice",77});
  35.     v.pb({"Mary",76});
  36.     for(auto p:v) cout<<p.na<<" "<<p.sc<<" 分\n"; cout<<"\n";
  37.     sort(ALL(v));
  38.     cout<<"排序後:\n";
  39.     for(auto p:v) cout<<p.na<<" "<<p.sc<<" 分\n"; cout<<"\n";
  40.     return 0;
  41. }
複製代碼
Allen

TOP

返回列表