您的位置:首页 > 其它

wyh2000 and a string problem(HDU5284)

2016-01-22 17:33 337 查看
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");

    }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  wyh2000 and a string