Codeforces contest 802 problem G

Codeforces contest 802 problem G Fake News (easy)

Description

As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess whether the given piece is true, but please be discreet about it...

Input

The first and only line of input contains a single nonempty string s of length at most 1000 composed of lowercase letters (a-z).

Output

Output YES if the string s contains heidi as a subsequence and NO otherwise.

Examples

//

Note

A string s contains another string p as a subsequence if it is possible to delete some characters from s and obtain p.

problem详见:http://codeforces.com/contest/802/problem/G

水模拟,只要注意一下小于其的长度即可!

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <algorithm>
#include <string>

using namespace std;

const int len = 100010;
char a[len];
string b="heidi";

bool pd(char a[],int n){
    bool ans;
    int i = 0;
     for (int j=0;j<5;j++) {
         ans = false;
         while (i<n) {
         if (a[i] == b[j]) {ans = true;i++;break;}
         i++;
         }
         if (!ans) return false;
     }
    return true;
}

int main() {
    //freopen("test.in","r",stdin);
    scanf("%s",a);
    int n = strlen(a);
    if (n==5 && a[0] == 'h' && a[1] == 'e' && a[2] == 'i'  && a[3] == 'd' && a[4] == 'i') cout << "YES" << endl;
    else {
      if (n <= 5) cout << "NO" << endl;
       else {
         if (pd(a,n)) cout << "YES" <<endl;
          else cout << "NO" << endl;
        }
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值