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.
The first and only line contains the word s, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
If Vasya managed to say hello, print "YES", otherwise print "NO".
ahhellllloou
YES
hlelo
NO
这道题,看完一遍题开始写,写完直接交了,一次都没有编译过……然后就A了
抱歉……你不能怪我轻视你,真的是你太水……
给一个字符串,问里面有没有hello这个子序列
那么……模拟即可
Code:
#include <cstdio>
#include <memory>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int flag=0;
string s; cin>>s;
for(int i=0;i<s.length();i++)
{
if(flag==0 && s[i]=='h')flag=1;
else if(flag==1 && s[i]=='e')flag=2;
else if(flag==2 && s[i]=='l')flag=3;
else if(flag==3 && s[i]=='l')flag=4;
else if(flag==4 && s[i]=='o')flag=5;
}
if(flag==5)cout<<"YES"<<endl;
else cout<<"NO"<<endl;
return 0;
}

本篇博客介绍了一个简单的编程挑战,任务是检查给定的字符串中是否存在hello作为子序列。通过示例解释了问题,并提供了一段C++代码实现,该代码通过迭代输入字符串来确定是否可以形成hello子序列。
2139

被折叠的 条评论
为什么被折叠?



