问题 L: Daydream

问题 L: Daydream

时间限制: 1 Sec   内存限制: 128 MB
提交: 337   解决: 97
[ 提交][ 状态][ 讨论版][命题人: admin]

题目描述

You are given a string S consisting of lowercase English letters. Another string T is initially empty. Determine whether it is possible to obtain S=T by performing the following operation an arbitrary number of times:
Append one of the following at the end of T: dream, dreamer, erase and eraser.

Constraints
1≤|S|≤105
S consists of lowercase English letters.

输入

The input is given from Standard Input in the following format:
S

输出

If it is possible to obtain S=T, print YES. Otherwise, print NO.

样例输入

erasedream

样例输出

YES

提示

Append erase and dream at the end of T in this order, to obtain S=T.




#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;
#define LL long long
#define N 100005
 
char b[8][20]={"dreameraser","dreamerase","dream","dreamer","erase","eraser"};
string c;
int pan(int i,int j,int f)
{
    int cnt=0;
    for(int k=i;k<j;k++)
    {
       // cout<<"k="<<k<<endl;
        if(c[k]!=b[f][cnt++])
        {
            //cout<<"no"<<endl;
            return false;
        }
    }
    return true;
}
bool judge( )
{
    int l=c.length();
    for(int i=0;i<2*l;i++)
    {
        if(pan(i,i+11,0))
        {
            i+=10;
        }
        else if(pan(i,i+10,1))
        {
            i+=9;
        }
        else if(pan(i,i+7,3))
        {
            i+=6;
        }
        else if(pan(i,i+5,2))
        {
            i+=4;
        }
        else if(pan(i,i+6,5))
        {
            i+=5;
        }
        else if(pan(i,i+5,4))
        {
            i+=4;
        }
        else return false;
        if(i>=l-1)return true;
    }
    return true;
}
int main()
{
    while(cin>>c)
    {
        if(judge())
        {
            cout<<"YES"<<endl;
        }
        else cout<<"NO"<<endl;
    }
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值