字符序列模式识别

来源:互联网 发布:数据库多少钱 编辑:程序博客网 时间:2024/06/09 20:12

题目描述

试写一个算法,识别字符序列是否为形如‘子序列1&子序列2’模式的字符序列,其中子序列2是子序列1的逆序列,0<子序列字符串长度<1000,且都为小写字母。输出YES或者NO。

输入格式

一行字符序列

输出

YES或NO

样例输入

hello&ollhe

样例输出

NO


#include <iostream>#include <string>using namespace std;int main(){    int len, i, flag;    string str;    while(1)    {        cin>>str;        len = str.length();        flag = 1;        for(i = 0; i<len/2; ++i)        {            if(str[i] != str[len - i - 1])                flag = 0;        }        if(flag)        {            cout<<"YES"<<endl;        }        else        {            cout<<"NO"<<endl;        }    }    return 0;}


0 0