- #include<bits/stdc++.h>
- using namespace std;
- struct student{
- string name;
- int score;
- };
- bool compare(student a,student b){
- return a.score>b.score;
- }
- student st[4];
- void show(){
- for(student s:st){
- cout<<s.name<<" "<<s.score<<"分"<<endl;
- }
- cout<<endl;
- }
- int main()
- {
- cin.tie(0);
- cin.sync_with_stdio(0);
- st[0].name="Bob";
- st[0].score=70;
- st[1].name="Cindy";
- st[1].score=66;
- st[2].name="Alice";
- st[2].score=77;
- st[3].name="Mary";
- st[3].score=76;
- show();
- sort(st,st+4,compare);
- show();
- return 0;
- }
複製代碼 |