UVA 384 - Slurpys

题意:根据所给要求,判断输入字符串是否满足要求
代码如下:
#include <bits/stdc++.h>

using namespace std;
char x[65];
bool Slump(char x[65],int &i)//判断字符串是否符合Slump
{
    if((x[i]=='D'||x[i]=='E')&&x[++i]=='F')
    {
        while(x[++i]=='F');
        if(x[i]=='G')return true;
        else if(x[i]=='D'||x[i]=='E')return Slump(x,i);
        else return false;
    }
    else return false;
}
bool Slimp(char x[65],int &i)//判断字符串是否符合Slimp
{
    if(x[i]=='A')
    {
        i++;
        if(x[i]=='H')return true;
        else if(x[i]=='B')
        {
            if(Slimp(x,++i)&&x[++i]=='C')
                return true;
            else return false;
        }
        else
        {
            if(Slump(x,i)&&x[++i]=='C')
                return true;
            else return false;
        }
    }
    else return false;
}
int main()
{
    int n,i;
    cin>>n;
    cout<<"SLURPYS OUTPUT"<<endl;
    while(n--)
    {
        cin>>x;
        i=0;
        if(Slimp(x,i)&&Slump(x,++i)&&i==(strlen(x)-1))//判断字符串是否符合Slurpy
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
    cout<<"END OF OUTPUT"<<endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/liuxinyu666/article/details/80095058