传智杯——志愿者
作者:互联网
将所有志愿者的属性全部包含在struct中,然后用sort进行排序,需要谓词
代码如下:
#include<iostream> #include<algorithm> using namespace std; typedef struct adf { int num; int t; int k; int sum = t * k; }VOL; VOL vol[900000]; bool mycmp(VOL one, VOL two) { if (one.sum != two.sum) return one.sum > two.sum; else if (one.t != two.t) return one.t > two.t; else return one.num < two.num; } int main(void) { int n; cin >> n; for (int i = 1; i <= n; i++) { vol[i].num = i; cin >> vol[i].t >> vol[i].k; vol[i].sum = vol[i].t * vol[i].k; } sort(vol + 1, vol + (n+1), mycmp); for (int i = 1; i <= n; i++) { cout << vol[i].num << " "; } return 0; }
标签:传智杯,志愿者,VOL,sum,two,vol,int,num 来源: https://www.cnblogs.com/loliconsk/p/14309734.html