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

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



