hdu5284--water, strlen pit--wyh2000 and a string problem

Source: Internet
Author: User

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

A subsequence of a stringsis a string the can be derived fromsBy 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 were asked to judge whetherWyhis a subsequence of some string or not, you just need to find a characterWAy, and anh, So, theWis in front of they, and theyis in front of theh.

One day a pupil holding a string asks him, ' isWyhA subsequence of this string? "
However, wyh2000 has severe myopia. If there is, or more consecutive charactervs, then he would see it as oneW. For example, the stringVVVwould be seen asW, the stringVVWVVVwould be seen as www , and the String  vwvv  will be seen As  vww .

How would wyh2000 answer this question?

 


Inputthe first line of the input contains an integerT(t≤5) , denoting the number of testcases.

N lines follow, each line contains a string.

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

The length of hack input must is no more than 100000.


Outputfor each string, you should the output one line containing one word. OutputYesIf wyh2000 would consider wyh as a subsequence of it, or No otherwise.


Sample input4woshiyangliwoyeshiyanglivvuuyehvuvuyeh 


Sample outputnoyesyesno 


Sourcebestcoder Round #48 ($)
/* Pit point: strlen complexity O (n) for String type O (1) */#include <cstdio> #include <cstring> #include <algorithm> using namespace Std;const int MAX = 3145728 + 5;char s[max];int main () {    int T;     scanf ("%d", &t);    while (t--) {        scanf ("%s", s);        int pos1 =-1, Pos2 =-1, pos3 =-1;        int n = strlen (s);    for (int i = 0; i < n;) {        if (s[i] = = ' V ' && s[i+1] = = ' V ' && pos1 = =-1) {            pos1 = i;            i + = 2;        }        else   if (s[i] = = ' W ' && pos1 = =-1) {            pos1 = i;            i++;        }        else   if (s[i] = = ' Y ' && pos1! =-1 && pos2 = = 1) {            pos2 = i;            i++;        }        else  if (s[i] = = ' h ' && pos2! =-1 && pos3 = = 1) {            pos3 = i;            i++;        }        else i++;    }    if (pos3! =-1) printf ("yes\n");    else printf ("no\n");    }    return 0;}

  

hdu5284--water, strlen pit--wyh2000 and a string problem

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.