Codeforces contest 802 problem G

来源:互联网 发布:菜鸟网络能上市吗? 编辑:程序博客网 时间:2024/06/04 19:32

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


原创粉丝点击