您的位置:首页 > 其它

The 6th Zhejiang Provincial Collegiate Programming Contest->ProblemA:Second-price Auction

2016-02-25 21:59 405 查看
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3202

题意:拍卖东西,以第二高价的价格卖给出第一高价的人。输出最后获得东西的人的序号和要出的价钱。

思路:(最笨的方法)用结构体来排序。

#include<bits/stdc++.h>
using namespace std;
struct hzx {
int id;
int a;
};
int comp1(const void *p,const void *q) {
return ((struct hzx *)p)->a-((struct hzx *)q)->a;
}
int main() {
int t,n;
struct hzx aa[101];
cin>>t;
while(t--) {
cin>>n;
for(int i=0; i<n; i++) {
cin>>aa[i].a;
aa[i].id=i;
}
qsort(aa,n,sizeof(struct hzx),comp1);
printf("%d %d\n",aa[n-1].id+1,aa[n-2].a);

}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: