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