//分为n==2和n!=2两种情况
AC代码:
#include <iostream>
using namespace std;
int main()
{
int n;
while (cin >> n)
{
int m, p;
if (n == 2)
{
cin >> m >> p;
if(m!=p)
cout << m << " " << 1 << endl;
else
cout << m << " " << 2<< endl;
}
else if (n != 2)
{
int a[n + 1];
int cnt = 1;//cnt为重复次数
int x;//x为连续重复次数最多的数
int max = 1;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
}
x=a[1];
for (int i = 2; i <= n; i++)
{
if (a[i] == a[i - 1])
{
cnt++;
if (cnt > max)
{
max = cnt;
x = a[i];
}
}
if (a[i] != a[i + 1])
{
cnt = 1;
}
}
cout << x << " " << max << endl;
}
}
//system("pause");
return 0;
}