HDU - 5284 wyh2000 and a string problem

本文介绍了一种特殊的字符串匹配问题,即如何在一个特定条件下判断一个字符串是否为另一个字符串的子序列。考虑到一种特殊的‘视力’限制,将连续的字符视为单一字符的情况,通过示例和代码展示了具体的实现方法。

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

Young theoretical computer scientist wyh2000 is teaching young pupils some basic concepts about strings.

A subsequence of a string
ss is a string that can be derived from ss by deleting some characters without changing the order of the remaining characters. You can delete all the characters or none, or only some of the characters.

He also teaches the pupils how to determine if a string is a subsequence of another string. For example, when you are asked to judge whether
wyhwyh is a subsequence of some string or not, you just need to find a character ww, a yy, and an hh, so that the ww is in front of the yy, and the yy is in front of the hh.

One day a pupil holding a string asks him, "Is
wyhwyh a subsequence of this string?"
However, wyh2000 has severe myopia. If there are two or more consecutive character
vvs, then he would see it as one ww. For example, the string vvvvvv will be seen as ww, the string vvwvvvvvwvvv will be seen as wwwwww, and the string vwvvvwvv will be seen as vwwvww.

How would wyh2000 answer this question?
Input
The first line of the input contains an integer T(T105)T(T105), denoting the number of testcases.

NN lines follow, each line contains a string.

Total string length will not exceed 3145728. Strings contain only lowercase letters.

The length of hack input must be no more than 100000.
Output
For each string, you should output one line containing one word. Output YesYes if wyh2000 would consider wyhwyh as a subsequence of it, or NoNo otherwise.
Sample Input
4
woshiyangli
woyeshiyangli
vvuuyeh
vuvuyeh
Sample Output
No
Yes
Yes
No

水题 理解题意 按描述处理字符串....
AC代码:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
char s[4000005];
int main()
{
    int t,temp[5],i,n;
    scanf("%d",&t);
    getchar();
    while(t--)
    {
        gets(s);
        n=strlen(s);
        memset(temp,0,sizeof(temp));
        for(i=0;i<n;i++)
        {
            if(s[i]=='w'||(s[i]=='v'&&s[i+1]=='v'))
            {
                temp[1]++;
            }
            else if(s[i]=='y'&&temp[1]!=0)
            {
                temp[2]++;
            }
            else if(s[i]=='h'&&temp[1]!=0&&temp[2]!=0)
            {
                temp[3]++;
            }
            if(temp[1]!=0&&temp[2]!=0&&temp[3]!=0)
            {
                printf("Yes\n");
                break;
            }
        }
        if(temp[1]==0||temp[2]==0||temp[3]==0)
        {
            printf("No\n");
        }
    }
    return 0;
}




























评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值