33:判断字符串是否为回文

来源:互联网 发布:利用python写网络爬虫 编辑:程序博客网 时间:2024/05/22 12:28

原题链接

总时间限制: 
1000ms 
内存限制: 
65536kB
描述

输入一个字符串,输出该字符串是否回文。回文是指顺读和倒读都一样的字符串。

输入
输入为一行字符串(字符串中没有空白字符,字符串长度不超过100)。
输出
如果字符串是回文,输出yes;否则,输出no。
样例输入
abcdedcba
样例输出
yes

源码

#include <iostream>#include <iomanip>#include <cstring>using namespace std;int main(){    char str[100],str2[100];    int i;    long len;    gets(str);    len = strlen(str);    for (i=0;i<len;i++){        str2[i] = str[len-i-1];    }    str2[i] = '\0';    if (strcmp(str, str2) == 0) cout << "yes";    else cout << "no";    return 0;}


原创粉丝点击