A - Second-price Auction
题意:找到输入最大值的下标,找到第二大值;第一个输出最大值的下标,第二个输出第二大值
代码:
#include <stdio.h>
#include <algorithm>
using namespace std;
bool cmp(int x,int y){
return x>y;
}
int main() {
int t;
while (scanf("%d",&t)!=EOF){
int n;
int pi[105];
while (t--){
scanf("%d",&n);
int max = 0;
int a = 1;
for (int i = 1;i <= n;i++){
scanf("%d",&pi[i]);
if (i == 1){
max = pi[1];
}
else {
if (pi[i] > max){
max = pi[i];
a = i;
}
}
}
sort(pi+1,pi+n+1,cmp);
int b = pi[2];
printf("%d %d\n",a,b);
}
}
}