using namespace std;
int main()
{
int N, count = 0, len = 0, max = 0, a = 0, b = 0;
cin >> N;
int *n = new int[N];
int *tmp = new int[N];
for (int i = 0; i < N; i++)
cin >> n[i];
for (int j = N; j > 0; j--)
{
if (j >= 2)
{
for (int i = 0; i <= N - j; i++)
{
a = 0;
count = 0;
for (int x = i; x < i + j; x++)
{
tmp[a] = n[x];
a++;
}
for (int x = 0; x <= N - j; x++)
{
b = 0;
for (int y = x; y < x + j; y++)
{
if (tmp[b] == n[y])
{
b++;
if (b == j)
{
b = 0;
count++;
}
}
else
break;
}
}
if (count > 1)
{
len = j;
if (len > max)
max = len;
}
}
}
else
{
for (int i = 0; i < N; i++)
{
count = 0;
tmp[0] = n[i];
for (int x = 0; x < N; x++)
{
if (tmp[0] == n[x])
count++;
}
if (count > 1)
{
len = j;
if (len > max)
max = len;
}
}
}
}
cout << max << endl;
return 0;
}
沒有留言:
張貼留言