问题 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.
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
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;
}
}