题目:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word s. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word s.
解题:个人想法是,再建一个数组存想要检索的子串,避免不断的if与else
#include<bits/stdc++.h>
using namespace std;
#define MAX 1000006
char a[MAX];
int main()
{
cin>>a;
char b[6]="hello";
int k=0;
for(int i=0; a[i]!='\0'; i++)
{
if(a[i]==b[k])k++;
}
if(k==5)cout<<"YES";
else cout<<"NO";
}