Skip to content

Instantly share code, notes, and snippets.

@completejavascript
Created September 15, 2018 08:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save completejavascript/39290d009ac77d74bd19997b31f2c8f7 to your computer and use it in GitHub Desktop.
Save completejavascript/39290d009ac77d74bd19997b31f2c8f7 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
const int MAX = 3005;
int GetLength(char *str)
{
int length = 0;
while(str[length] != '\0') length++;
return length;
}
int main()
{
ios::sync_with_stdio(false);
//freopen("input.txt","r",stdin);
int T, length, len_sub, numAnswer;
char str[MAX];
bool finish;
cin >> T;
for(int tc = 0; tc < T; tc++)
{
cin >> str;
length = GetLength(str);
len_sub = length;
while(true)
{
numAnswer = 0;
finish = false;
for(int i = 0; i < length; i++)
{
if(i + len_sub > length) break;
if(len_sub == 1 || (len_sub == 2 && str[i] == str[i+1]))
{
numAnswer++;
finish = true;
}
else
{
bool check = true;
for(int j = 0; j <= (len_sub - 1)/2; j++)
if(str[j + i] != str[len_sub - 1 - j + i])
{
check = false;
break;
}
if (check == true)
{
numAnswer++;
finish = true;
}
}
}
if (finish == true) break;
if (len_sub == 1) break;
len_sub--;
}
cout << len_sub << " " << numAnswer << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment