U:判断字符串是否为回文
- 总时间限制:
- 1000ms
- 内存限制:
- 65536kB
- 描述
-
输入一个字符串,输出该字符串是否回文。回文是指顺读和倒读都一样的字符串。
- 输入
- 输入为一行字符串(字符串中没有空白字符,字符串长度不超过100)。
- 输出
- 如果字符串是回文,输出yes;否则,输出no。
- 样例输入
-
abcdedcba
- 样例输出
-
yes
1 #include <iostream> 2 #include <string> 3 using namespace std; 4 int main() 5 { 6 string s; 7 cin >> s; 8 int count = 0; 9 for (int i=0;i<s.length();++i) 10 { 11 if (s[i]==s[s.length()-i-1]) 12 { 13 count++; 14 } 15 } 16 if (s.length()==count) 17 { 18 cout << "yes"; 19 } 20 else 21 { 22 cout << "no"; 23 } 24 return 0; 25 }
道阻且长,行则将至

浙公网安备 33010602011771号