wyh2000 and a string problem(HDU5284)


D - wyh2000 and a string problem
Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u
Submit Status Practice HDU 5284

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

A subsequence of a string $s$ is a string that can be derived from $s$ 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 $\text{wyh}$ is a subsequence of some string or not, you just need to find a character $\text{w}$, a $\text{y}$, and an $\text{h}$, so that the $\text{w}$ is in front of the $\text{y}$, and the $\text{y}$ is in front of the $\text{h}$.

One day a pupil holding a string asks him, "Is $\text{wyh}$ a subsequence of this string?"
However, wyh2000 has severe myopia. If there are two or more consecutive character $\text{v}$s, then he would see it as one $\text{w}$. For example, the string $\text{vvv}$ will be seen as $\text{w}$, the string $\text{vvwvvv}$ will be seen as $\text{www}$, and the string $\text{vwvv}$ will be seen as $\text{vww}$.

How would wyh2000 answer this question?
 

Input
The first line of the input contains an integer $T(T\le 10^5)$, denoting the number of testcases.

$N$ 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 $\text{Yes}$ if wyh2000 would consider $\text{wyh}$ as a subsequence of it, or $\text{No}$ otherwise.
 

Sample Input

4
woshiyangli
woyeshiyangli
vvuuyeh
vuvuyeh

 

Sample Output

No
Yes
Yes
No
题意:如果出现vv就被看成w,如果符合w在yde前面且y在h的前面,就输出Yes,否则输出No
#include<stdio.h>
#include<string.h>
int main()
{
    char a[200000];  //这里要开大,要不然会超时,我之前开了100005,结果超时了
    int t;
    scanf("%d",&t);
    while(t--)
    {
         scanf("%s",a);
         int w=0,y=0,h=0;     //提前标记,很多题都是这样的
         int l=strlen(a);      //这里最好定义一个变量为字符串长度,如果下面情况多了有可能会超时,我之前做过一道这样的题
         for(int i=0;i<l;i++)
         {
             if(w==0&&a[i]=='w')  
             {
                 w=1;       //符合题意就把w变为1
                 continue;  //这里结束本层循环,执行下一步
             }
             if(w==0&&i>=1&&a[i]=='v'&&a[i-1]=='v')   //注意i>=1,因为要保证这个和前一个全部为v
             {
                 w=1;
                 continue;
             }
             if(w==1&&y==0&&a[i]=='y')  //在上一步成立的情况下走下一步
             {
                 y=1;
                 continue;
             }
             if(w==1&&y==1&&h==0&&a[i]=='h')   //上俩步都成立,走下一步
             {
                 h=1;
                 break;  //已经符合情况了,直接跳出循环
             }
         }
         if(w==1&&y==1&&h==1)  //三个条件都成立
         printf("Yes\n");
         else printf("No\n");
    }
}
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值