- #include<bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define int ll
- #define FOR(i,a,b) for(int i=a;i<b;i++)
- #define REP(i,n) FOR(i,0,n)
- #define REP1(i,n) FOR(i,1,(n)+1)
- #define RREP(i,n) for(int i=(n)-1;i>=0;i--)
- #define f first
- #define s second
- #define pb push_back
- #define ALL(x) x.begin(),x.end()
- #define SZ(x) (int)(x.size())
- #define SQ(x) (x)*(x)
- #define pii pair<int,int>
- #define Graph vector<vector<int>>
- #define IOS() cin.sync_with_stdio(0),cin.tie(0),cout.tie(0)
- const ll inf=(1ll<<63)-1;
- const int maxn=1e5+5;
- const ll mod=1e9+7;
- struct P {
- string na;
- int sc;
- };
- vector<P> v;
- bool operator<(P a,P b) {
- return a.sc<b.sc;
- }
- signed main()
- {
- IOS();
- v.pb({"Bob",70});
- v.pb({"Cindy",66});
- v.pb({"Alice",77});
- v.pb({"Mary",76});
- for(auto p:v) cout<<p.na<<" "<<p.sc<<" 分\n"; cout<<"\n";
- sort(ALL(v));
- cout<<"排序後:\n";
- for(auto p:v) cout<<p.na<<" "<<p.sc<<" 分\n"; cout<<"\n";
- return 0;
- }
複製代碼 |