本文最后更新于 1170 天前,其中的信息可能已经有所发展或是发生改变。
代码语言:javascript复制// 洛谷1723 高手过愚人节.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<iostream>
#include<string>
#include<cstring>
#pragma warning(disable:4996)
using namespace std;
int main()
{
int n, i=0;
cin >> n;
while (i < n)
{
int len,j,k,m,sum=0,sum1=0;
string str;
cin>>str;
len = str.length();
char *ch = new char[len];
strcpy(ch, str.c_str());
/*
for (j = 0; j < len; j )
{
for (k = j 1; k < len; k )
{
if (ch[j] == ch[k])
{
for (m = 0; m <= (j - i) / 2; m )
{
if (ch[j m 1] != ch[k - m - 1])
break;
if (m == (j - i) / 2)
sum1 = k-j 1;
}
}
if (sum1>sum)
{
sum = sum1;
}
}
}
*/
for (j = 1; j < 2 * len; j )
{
if (j%2!=0&&ch[(j-1)/2] == ch[(j 1)/2])
{
m = 0;
while ((j - 2*m-1) >= 0 && (j 2*m 1)<2 * len)
{
if (ch[(j - 2 * m - 1)/2] != ch[(j 2 * m 1)/2])
break;
sum1 = 2 * (m 1);
m ;
}
}
if (j % 2 == 0 && ch[(j - 2)/2] == ch[(j 2)/2])
{
m = 1;
while ((j - 2 * m ) >= 0 && (j 2 * m )<2 * len)
{
if (ch[(j - 2 * m)/2 ] != ch[(j 2 * m)/2 ])
break;
sum1 = 2 * m 1;
m ;
}
}
if (sum1>sum)
{
sum = sum1;
}
}
cout << sum;
i ;
}
return 0;
}
Post Views: 175