Palindrome
Palindrome
Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^
题目描述
A string is said to be a palindrome if it reads the same both forwards and backwards, for example “madam” is a palindrome while “acm” is not.
Now we want to know how many palindrome strings in the given strings.
输入
The first line of the input contains a single integer T, which indicates number of the given strings.
The next T lines contain one string S, whose length is less than 1000 letters.
输出
One integer indicates the number of palindrome strings.
示例输入
5
ababa
aabb
ab
cccccc
Abcd
示例输出
2
#include<stdio.h>
#include<string.h>
char a[1001];
int main()
{
int i,j,n,m,k,t=0;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%s",a);
m=strlen(a);
k=0;
for(j=0;j<(m+1)/2;j++)
if(a[j]==a[m-j-1])
k++;
if(k==(m+1)/2)
t++;
}
printf("%d\n",t);
}
还没有评论,来说两句吧...