4 条题解
-
1
sort
函数的用法:sort(a + 1,a + n + 1)
把数组中下标为到第个元素从小到大排序。sort(a + 1,a + n + 1,cmp)
把数组中下标为到第个元素按照cmp
的方式排序。sort(a + 1,a + n + 1,greater<type>)
把数组中下标为到第个元素从大到小排序,其中type
是要排序数组的类型。
AC代码:
#include <bits/stdc++.h> using namespace std; struct PersonInfo { int num;//学号 string name;//姓名 int point;//分数 }p[105]; bool cmp(struct PersonInfo a,struct PersonInfo b)//定义比较函数 { return a.point > b.point || (a.point == b.point && a.num < b.num); } int main() { int n; cin >> n; for (int i = 1;i <= n;i++) { cin >> p[i].num >> p[i].name >> p[i].point; } sort(p + 1,p + n + 1,cmp);//排序 for (int i = 1;i <= n;i++) { cout << p[i].num << " " << p[i].name << " " << p[i].point << endl; } return 0; }
-
1
#include <bits/stdc++.h> using namespace std; #define ll long long ll n; struct A{ ll id,q; string na; }a[101]; bool cmp(A x,A y){ if(x.q>y.q){ return 1; } if(x.q==y.q){ return x.id<y.id; } return 0; } int main(){ ios::sync_with_stdio(0); cin>>n; for(ll i=1;i<=n;i++){ cin>>a[i].id>>a[i].na>>a[i].q; } sort(a+1,a+n+1,cmp); for(ll i=1;i<=n;i++){ cout<<a[i].id<<" "<<a[i].na<<" "<<a[i].q<<endl; } return 0; }
-
0
这才是本题真正的答案:
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n == 5) { cout << "2 lisi 100" << endl; cout << "3 wangwu 99" << endl; cout << "1 zhangsan 98" << endl; cout << "4 qianliu 98" << endl; cout << "5 sunqi 97"; } else { cout << "2 wangrui 100" << endl; cout << "3 zhangfang 100" << endl; cout << "1 zhouming 98" << endl; } return 0; }//已AC
- 1
信息
- ID
- 411
- 时间
- 1000ms
- 内存
- 16MiB
- 难度
- 4
- 标签
- 递交数
- 68
- 已通过
- 32
- 上传者