第二题,粘贴得太着急了,把#include<iostream>粘在 //soure code里了,哎,太伤心了。
但是不放弃,自己调试后,发现测试用例可以通过的呢!这里贴一下自己的代码吧!如果有什么没有没想到的,求指出!
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int length;
int a[300];
cin >> length;
int i = 0;
int j = 1;
int temp = 0;
int k = 0;
int count = 0;
for (i = 0 ; i < length ; i++)
{
cin >> a[i];
}
while(j < length)
{
k = 0;
for(i = 0 ; i < j; i ++ )
{
if(a[j + k] == a[i])
{
k ++;
temp ++;
if(i == (j-1))
{
if(temp > count)
{
count = temp;
}
temp = 0;
}
continue;
}
if(temp > count)
{
count = temp;
}
k = 0 ;
temp = 0;
}
j ++ ;
}
cout << count << endl;
return 0;
}