中文题目题意就不多说了,这里面要注意,数的范围太大,不能用数组来计数,下面是一种比较巧妙的方式,刚开始我确实没想到,以前写过类似的忘了这种方法,详情看代码:
#include<set>
#include<map>
#include<stack>
#include<cmath>
#include<queue>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
typedef long long ll;
const int maxn = 20000010;
const int seed = 131;
const ll MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
using namespace std;
int main() {
int n;
while (scanf("%d", &n) != EOF)
{
ll num;
scanf("%lld", &num);
int sum = 1;
ll y = num;
for (int i = 2; i <= n; i++)
{
scanf("%lld", &num);
if (sum == 0)
{
y = num;
sum = 1;
}
else if (num == y)
sum++;
else
sum--;
}
printf("%lld\n", y);
}
return 0;
}