zoj 3202 Second-price Auction

//找出第二大的数和第一大的数的位置!
#include "iostream"
#include "memory.h"
using namespace std;

int p[110];

int main()
{
	int tc, n, i, max, smax, pos;
	cin >> tc;
	while (tc--)
	{
		cin >> n;
		memset(p, 0, sizeof(p));
		smax = -1;
	    pos = 0;
		for (i = 0; i < n; i++)
			cin >> p[i];
		max = p[0];
		for (i = 1; i < n; i++)
		{
			if (p[i] > max)
			{
				if (max > smax)
					smax = max;
				pos = i;
				max = p[i];
			}
			else if (p[i] > smax)
				smax = p[i];
		}
		cout << pos + 1 << " " << smax << endl;
	}
}

你可能感兴趣的:(zoj 3202 Second-price Auction)