题目:判断字符串是否为回文

tech2025-10-29  0

【题目描述】

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

【输入】

输入为一行字符串(字符串中没有空白字符,字符串长度不超过100)

【输出】

如果字符串是回文,输出yes;否则,输出no

【样例输入】

abcdedcba

【样例输出】

yes

【源代码】

#include <iostream> #include <cstring> using namespace std; char str[101]; int main() { int len; gets(str); len = strlen(str); for (int i = 0, j = len - 1; i < len, j >= 0; i++, j--) { if (str[i] != str[j]) { cout << "no"; break; } if (i > j) { cout << "yes"; break; } } return 0; }
最新回复(0)