CF802G Fake News (easy)

本文介绍了一个简单的字符串匹配问题——判断一个字符串是否包含特定子序列。通过实例演示了如何使用队列来跟踪目标子序列,并提供了完整的C++代码实现。

题意翻译

给定一个字符串询问能否听过删除一些字母使其变为“heidi”

如果可以输出“YES”,不然为“NO”

题目描述

As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess whether the given piece is true, but please be discreet about it...

输入输出格式

输入格式:

 

The first and only line of input contains a single nonempty string ss of length at most 10001000 composed of lowercase letters (a-z).

 

输出格式:

 

Output YES if the string ss contains heidi as a subsequence and NO otherwise.

 

输入输出样例

输入样例#1: 复制
abcheaibcdi
输出样例#1: 复制
YES
输入样例#2: 复制
hiedi
输出样例#2: 复制
NO

说明

A string ss contains another string pp as a subsequence if it is possible to delete some characters from ss and obtain pp .

#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
char ch[1100];
queue<char> que;
int main() {
    que.push('h');que.push('e');que.push('i');
    que.push('d');que.push('i');cin>>ch;
    int len=strlen(ch);
    for(int i=0;i<len;i++)
        if(!que.empty())
            if(ch[i]==que.front())
                que.pop();
    if(que.empty())    cout<<"YES";
    else    cout<<"NO";
}

 

 

转载于:https://www.cnblogs.com/cangT-Tlan/p/8442874.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值