6491: Daydream(思维)

6491: Daydream

时间限制: 1 Sec   内存限制: 128 MB
提交: 348   解决: 100
[ 提交][ 状态][ 讨论版][命题人: 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<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
int main()
{
    char s[100005], a[6][100]={"dream", "dreamer", "erase", "eraser", "dreamerase", "dreameraser"};
    scanf("%s", s);
    int len=strlen(s), sum=0;
    for(int i=0;i<len;i++)//还需要注意顺序
    {
        if(strncmp(s+i, a[5], 11)==0)
        {
            sum+=11;
            i+=10;
        }
        else if(strncmp(s+i, a[4], 10)==0)
        {
            sum+=10;
            i+=9;
        }
        else if(strncmp(s+i, a[3], 6)==0)
        {
            sum+=6;
            i+=5;
        }
        else if(strncmp(s+i, a[2], 5)==0)
        {
            sum+=5;
            i+=4;
        }
        else if(strncmp(s+i, a[1], 7)==0)
        {
            sum+=7;
            i+=6;
        }
        else if(strncmp(s+i, a[0], 5)==0)
        {
            sum+=5;
            i+=4;
        }
    }
    if(sum==len)
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
} 
/**************************************************************
    Problem: 6491
    User: ldu_reserver201701
    Language: C++
    Result: 正确
    Time:0 ms
    Memory:1092 kb
****************************************************************/

猜你喜欢

转载自blog.csdn.net/qq_30796379/article/details/80498941