微软编程一小时问题2:Longest Repeated Sequence

第二题,粘贴得太着急了,把#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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值