C - 白昼夢 / Daydream(模拟)

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: dreamdreamererase and eraser.

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

题意:

给你一个字符串,让你判断能不能由dreamdreamererase  and  eraser.这四个字符串组成这个字符串。

这里有一个坑:dreamereraser 的要判断一下。

代码:
 

#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;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值