链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=495

 

直接暴力

 

#include <stdio.h>
#include <string.h>
char s[100];

int main()
{
	bool isplalindrome(int l);
	int t;
	int l;
	int i,j;
	bool sign;
	scanf("%d",&t);
	int k;
	while(t--)
	{
		scanf("%s",s);
		l=strlen(s);
		if(isplalindrome(l))
			printf("%s\n",s);
		else
		{
			for(i=0;i<l;i++)
			{
				k=l;
				for(j=i;j>=0;j--)
					s[k++]=s[j];
				s[k]='\0';
				if( isplalindrome(k) )
					break;
			}
			printf("%s\n",s);
		}

	}
	return 0;
}

bool isplalindrome(int l)
{
	int i,j;

	for (i=0,j=l-1;i<j;i++,j--)
	{
		if(s[i]!=s[j])
			return false;
	}
	return true;

}