HDU2029 Palindromes _easy version回文串

Time Limit: 2000/1000 MS (Java/Others)

Memory Limit: 65536/32768 K (Java/Others)
[显示标签]
Description
“回文串”是一个正读和反读都一样的字符串,比如“level”或者“noon”等等就是回文串。请写一个程序判断读入的字符串是否是“回文”。
Input
输入包含多个测试实例,输入数据的第一行是一个正整数n,表示测试实例的个数,后面紧跟着是n个字符串。
Output
如果一个字符串是回文串,则输出"yes",否则输出"no".
Sample Input

4
level
abcde
noon
haha

Sample Output

yes
no
yes
no

Hint
lcy
Source
   C语言程序设计练习(五)  
Related problem
2024 2032 2030 2039 2034

直接上代码咯:

#include <iostream>
#include <string>
using namespace std;
int main()
{
int n;
cin>>n;
while(n--)
{
    string s;
    cin>>s;
    int i;
    for(i=0;i<s.size()/2;i++)
    {
        if(s[i]!=s[s.size()-i-1])
        {
            cout<<"no"<<endl;
                break;
        }
    }
        if(i==s.size()/2||i==s.size()/2+1)
            cout<<"yes"<<endl;
}
}

猜你喜欢

转载自blog.csdn.net/qq_41627235/article/details/82812780