华为測试 字符串运用-password截取

Catcher是MCA国的情报员,他工作时发现敌国会用一些对称的password进行通信,比方像这些ABBA。ABA,A,123321,可是他们有时会在開始或结束时增加一些无关的字符以防止别国破解。比方进行下列变化 ABBA->12ABBA,ABA->ABAKK,123321->51233214 。由于截获的串太长了,并且存在多种可能的情况(abaaab可看作是aba,或baaab的加密形式),Cathcer的工作量实在是太大了,他仅仅能向电脑高手求助,你能帮Catcher找出最长的有效password串吗?

输入一个字符串

返回有效password串的最大长度

例子输入:abba

例子输出:4

#include<iostream>
#include<string>
using namespace std;
int main()
{
	string str;
	cin>>str;
	string temp;
	int SIZE,BigLen=0;
	bool sign;
	for(string::size_type index1=0;index1!=str.size();++index1)
	{
		for(string::size_type index2=index1;index2!=str.size();++index2)
		{
			sign=1;
			temp.push_back(str[index2]);
			SIZE=temp.size();
			if(SIZE==1)
			{
				if(BigLen==0)
					++BigLen;
			}
			else
			if(SIZE>1)
			{
				for(string::size_type index3=0;index3!=SIZE/2;++index3)
				{
					if(temp[index3]!=temp[SIZE-1-index3])
						sign=0;
				}
				if(sign==1)
				{
					if(SIZE>BigLen)
						BigLen=SIZE;
				}
			}
			 
		}
		temp.clear();
	}
	cout<<BigLen<<endl;
	return 0;
}