【水模拟】#54 A. Chat room

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A. Chat room
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Input

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.

Output

If Vasya managed to say hello, print "YES", otherwise print "NO".

Sample test(s)
input
ahhellllloou
output
YES
input
hlelo
output
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;
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

糖果天王

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值