2 条题解
-
0
#include<bits/stdc++.h> using namespace std; struct wyy{ string b; int x; }a[10005]; bool cmp(wyy i,wyy k){ if(i.x==k.x){ return i.b<k.b; } return i.x>k.x; } int main(){ int t; cin>>t; for(int i=1;i<=t;i++){ cin>>a[i].b>>a[i].x; } sort(a+1,a+t+1,cmp); for(int i=1;i<=t;i++){ cout<<a[i].b<<" "<<a[i].x<<"\n"; } return 0; } -
0
学习一下这种输入方式
#include<bits/stdc++.h> using namespace std; struct Student{ int score; string name; }; bool cmp(Student &a, Student &b) { if(a.score != b.score){ return a.score > b.score; } return a.name < b.name; } int main() { int n; cin>>n; vector<Student> stu(n); //定义一个数据类型为 Student,大小为n的stu数组 for(int i = 0;i < n;i++) { cin>>stu[i].name>>stu[i].score; } sort(stu.begin(),stu.end(),cmp) ; //vector 排序的方法是使用 begin for(int i = 0;i < n;i++) { cout<<stu[i].name<<" "<<stu[i].score<<endl; } return 0; }
- 1
信息
- ID
- 354
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 1
- 标签
- 递交数
- 649
- 已通过
- 241
- 上传者