60分求助
查看原帖
60分求助
959900
moment_forever楼主2023/10/19 19:33
#include <bits/stdc++.h>
using namespace std;
int n, a[200005], uv, ans = 0;

int sort_1() {
	for (int i = 1; i <= n; i++) {
		for (int j = i + 1; j <= n; j++) {
			if (a[i] > a[j]) {
				uv = a[i];
				a[i] = a[j];
				a[j] = uv;
			}
			if (a[i] == a[j]) {
				for (int k = i; k >= 0; k--)
					a[k] = a[k - 1];
				ans++;
			}
		}
	}
	return 1;
}

int main() {
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	sort_1();

	if (n-ans < 2)
		cout << -1;
	else if (n == 3)
		cout << a[n - 1];
	else
		cout << a[n - 2];
	return 0;
}

2023/10/19 19:33
加载中...