Palindrome

矫情吗;* 2022-08-10 06:12 174阅读 0赞

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.

示例输入

  1. 5
  2. ababa
  3. aabb
  4. ab
  5. cccccc
  6. Abcd

示例输出

  1. 2
  2. #include<stdio.h>
  3. #include<string.h>
  4. char a[1001];
  5. int main()
  6. {
  7. int i,j,n,m,k,t=0;
  8. scanf("%d",&n);
  9. for(i=0;i<n;i++)
  10. {
  11. scanf("%s",a);
  12. m=strlen(a);
  13. k=0;
  14. for(j=0;j<(m+1)/2;j++)
  15. if(a[j]==a[m-j-1])
  16. k++;
  17. if(k==(m+1)/2)
  18. t++;
  19. }
  20. printf("%d\n",t);
  21. }

发表评论

表情:
评论列表 (有 0 条评论,174人围观)

还没有评论,来说两句吧...

相关阅读