CF-Chat room

本文讨论了Vasya在聊天室尝试通过删除字符的方式形成'hello'的过程,判断他是否成功传达问候。代码示例展示了如何通过编程检查输入字符串中是否包含完整的'hello'

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

题目:

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


}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值