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

来源:互联网 发布:centos 7开机密码忘记 编辑:程序博客网 时间:2024/06/05 18:16

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;}
0 0
原创粉丝点击