HDU5284——水,strlen坑——wyh2000 and a string problem

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 wyh is a subsequence of some string or not, you just need to find a character w, a y, and an h, so that the w is in front of the y, and the y is in front of the h.

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

How would wyh2000 answer this question?

Input

The first line of the input contains an integer T(T≤105), 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 Yes if wyh2000 would consider wyh as a subsequence of it, or No otherwise.

Sample Input

4
woshiyangli
woyeshiyangli
vvuuyeh
vuvuyeh

Sample Output

No
Yes
Yes
No

Source

BestCoder Round #48 ($)

/*
坑点:
strlen的复杂度为O(n)
对于string型的复杂度为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;
}

  

时间: 2024-08-25 15:34:55

HDU5284——水,strlen坑——wyh2000 and a string problem的相关文章

bestcoder 47# wyh2000 and a string problem (水题)

wyh2000 and a string problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Total Submission(s): 484    Accepted Submission(s): 232 Problem Description Young theoretical computer scientist wyh2000 is teaching you

HDU 5284 wyh2000 and a string problem(字符串,水)

题意:比如给你一个串,要求判断wyh是不是它的子序列,那么你只需要找一个w,找一个y,再找一个h,使得w在y前面,y在h前面即可.有一天小学生拿着一个串问他“wyh是不是这个串的子序列?”.但是wyh2000有重度近视眼,如果字符串中有一段连续的v(至少两个),那么他会把它看成一个w.例如,字符串vvv会被看成w,字符串vvwvvv会被看成www,字符串vwvv会被看成vww.请问wyh2000会怎么回答这个问题?输出yes和no. 思路:其实就是将两个以上的v换成w,再来看是否能有'wyh'子

hdu 5284 wyh2000 and a string problem(没有算法,只考思维,字符数组得开20万,不然太小了)

代码: #include<cstdio> #include<cstring> using namespace std; char s[200000]; int main() { int t; scanf("%d",&t); while(t--) { scanf("%s",s); int w=0,y=0,h=0; int len=strlen(s); for(int i=0; i<len; i++) { if(w==0&&

HDU 5284 wyh2000 and a string problem(错误总结)

---恢复内容开始--- 题目链接:戳我(英文),戳我(中文) 题目大意: 看中文 样例解释: 略 解题思路: for循环跑一遍,遇到 vv 就变成 w 就行了 错误的代码 int k = 0, i; for(i = 0; str[i+1]; i++) { printf("%d %c\n", i, str[i]); if(str[i] == 'v' && str[i+1] == 'v') { i = i + 1; //这里不能加1 str[i] = 'w'; //k++

[Water]Hdu 5284 wyh2000 and a string problem

#include <cstdio> #include <cstring> using namespace std; const int MAXN=10000000+5; char a[MAXN]; int t; char b[3]={'w','y','h'}; int main() { scanf("%d",&t); getchar(); while(t--){ gets(a); for(int i=0;a[i+1];++i)if(a[i]=='v'&a

HDU-5284-wyh2000 and a string problem(BestCoder Round #48 ($))

wyh2000 and a string problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Total Submission(s): 492    Accepted Submission(s): 239 Problem Description Young theoretical computer scientist wyh2000 is teaching you

hdu 5008(2014 ACM/ICPC Asia Regional Xi&#39;an Online ) Boring String Problem(后缀数组&amp;二分)

Boring String Problem Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 219    Accepted Submission(s): 45 Problem Description In this problem, you are given a string s and q queries. For each que

HDU 5008 Boring String Problem(西安网络赛B题)

HDU 5008 Boring String Problem 题目链接 思路:构造后缀数组,利用height的数组能预处理出每个字典序开始的前缀和有多少个(其实就是为了去除重复串),然后每次二分查找相应位置,然后在往前往后找一下sa[i]最小的 代码: #include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; const int

HDOJ3374 String Problem [KMP最小循环节点]+[最小(大)表示法]

String Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1442    Accepted Submission(s): 645 Problem Description Give you a string with length N, you can generate N strings by left shifts