Problem Statement
You are given a string SS consisting of lowercase English letters. Another string TT is initially empty. Determine whether it is possible to obtain S=TS=T by performing the following operation an arbitrary number of times:
- Append one of the following at the end of TT:
dream
,dreamer
,erase
anderaser
.
Constraints
- 1≦|S|≦1051≦|S|≦105
- SS consists of lowercase English letters.
Input
The input is given from Standard Input in the following format:
SS
Output
If it is possible to obtain S=TS=T, print YES
. Otherwise, print NO
.
Sample Input 1 Copy
Copy
erasedream
Sample Output 1 Copy
Copy
YES
Append erase
and dream
at the end of TT in this order, to obtain S=TS=T.
Sample Input 2 Copy
Copy
dreameraser
Sample Output 2 Copy
Copy
YES
Append dream
and eraser
at the end of TT in this order, to obtain S=TS=T.
Sample Input 3 Copy
Copy
dreamerer
Sample Output 3 Copy
Copy
NO
题意:
给你一个字符串,让你判断能不能由dream
, dreamer
, erase
and eraser
.这四个字符串组成这个字符串。
这里有一个坑:dreamer和eraser 的要判断一下。
代码:
#include<bits/stdc++.h>
using namespace std;
char a[100009];
char p[]= {'d','r','e','a','m','e','r'};
char q[]= {'e','r','a','s','e','r'};
int main()
{
scanf("%s",&a);
int n=strlen(a);
int d=0;
int e=0;
for(int i=0; i<n; i++)
{
if(d==0&&e==0)
{
if(a[i]=='d')
{
d++;
}
else if(a[i]=='e')
{
e++;
}
else
{
cout<<"NO"<<endl;
return 0;
}
continue;
}
else if(e==0&&d)
{
if(d<5)
{
if(a[i]!=p[d])
{
cout<<"NO"<<endl;
return 0;
}
if(a[i]==p[d])
{
d++;
}
if(d==5)
{
if(i==n-1)
{
cout<<"YES"<<endl;
return 0;
}
else if(a[i+3]=='a'||a[i+1]=='d')
{
d=0;
}
}
continue;
}
else if(d<7)
{
if(a[i]!=p[d])
{
cout<<"NO"<<endl;
return 0;
}
if(a[i]==p[d])
{
d++;
}
if(d==7)
{
if(i==n-1)
{
cout<<"YES"<<endl;
return 0;
}
else
{
d=0;
}
}
continue;
}
continue;
}
else if(d==0&&e)
{
if(e<5)
{
if(a[i]!=q[e])
{
cout<<"NO"<<endl;
return 0;
}
if(a[i]==q[e])
{
e++;
}
if(e==5&&i==n-1)
{
cout<<"YES"<<endl;
return 0;
}
if(e==5&&a[i+1]!='r')
{
e=0;
}
continue;
}
else if(e<6)
{
if(a[i]!=q[e])
{
cout<<"NO"<<endl;
return 0;
}
if(a[i]==q[e])
{
e++;
}
if(e==6)
{
if(i==n-1)
{
cout<<"YES"<<endl;
return 0;
}
else
{
e=0;
}
}
}
}
}
cout<<"NO"<<endl;
}