BUCTOJ_ACM2017C 回文串的热爱

#include "iostream"
#include "algorithm"
#include "cstdio"
#include "cstring"
using namespace std;

int main()
{
    string s;
    int n;
    cin >> n;
    while(n--)
    {
        cin >> s;
        int len;
        int flag = 0;
        len = s.length();
        for(int i=0;i < len/2;i++)
        {
            if(s[i] != s[len-i-1])
                flag++;
        }
        if(flag == 0 && len%2 == 1)
            cout << "YES"<<endl;
        else if(flag == 1)
            cout << "YES"<< endl;
        else
            cout << "NO"<<endl;
    }
    return 0;
}

1.计算字符串的长度 s.length()

转载于:https://www.cnblogs.com/cunyusup/p/7704523.html

你可能感兴趣的:(BUCTOJ_ACM2017C 回文串的热爱)