题目1192:回文字符串

题目1192:回文字符串

时间限制:1 秒

内存限制:32 兆

特殊判题:

提交:4682

解决:2243

题目描述:

给出一个长度不超过1000的字符串,判断它是不是回文(顺读,逆读均相同)的。

输入:

输入包括一行字符串,其长度不超过1000。

输出:

可能有多组测试数据,对于每组数据,如果是回文字符串则输出"Yes!”,否则输出"No!"。

样例输入:
hellolleh
helloworld
样例输出:
Yes!
No!
来源:
2007年华中科技大学计算机研究生机试真题
答疑:
解题遇到问题?分享解题心得?讨论本题请访问:http://t.jobdu.com/thread-7915-1-1.html
先用两个数组存就是运行错误,后来改成直接对比判断才对的,贴出来警惕一下
#include<stdio.h>
#include<string.h>
char str[1010];
char a[510],b[510];
int main()
{
    while(gets(str)!=NULL)
    {
        int flag=1;
        for(int i=0,j=strlen(str)-1;i<(strlen(str)+1)/2;i++,j--)
        {
            if(str[i]!=str[j])
          {
                  flag=0;
                  break; 
            }
        }
        if(flag)
            printf("Yes!
");
        else printf("No!
");
    }
    return 0;
}
彼时当年少,莫负好时光。
原文地址:https://www.cnblogs.com/l609929321/p/6591477.html