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 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 ($)

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
char s[40000000];
char str[5]={"wyh"};
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%s",s);

        int len = strlen(s);

        int id=0;

        for(int i = 0;i < len;i++)
        {
            if(id==3) break;
            if(s[i]==str[id]) id++;
            if(id==0 && s[i]=='v' && s[i+1]=='v') id++;
        }
//        printf("%d\n",id);
        if(id==3) printf("Yes\n");
        else printf("No\n");
    }
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-08-03 21:26:45

bestcoder 47# wyh2000 and a string problem (水题)的相关文章

sdut 2841 Bit Problem (水题)

题目 贴这个题是因为看题解有更简单的方法, 我做的时候是直接算的, 也很简单. 贴一下题解吧: 如果一个整数不等于 0,那么该整数的二进制表示中至少有一位是 1. 这个题结果可以直接输出 x - (x&(x-1)); 因为x-1 之后二进制下,就是最右边的1变成了0, 最右边的1的 右边所有的0变成了1, 不影响最左边. 我的代码: 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4

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 charac

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

BestCoder Round #36 (hdu5198)Strange Class(水题)

转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Strange Class Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Description In Vivid’s school, there is a strange class(SC). In SC, the students’ nam

HDU 6182 A Math Problem 水题

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=6182 题目描述: 输入N, 输出满足k^k <= N 的 k的个数 解题思路: 水水更健康 代码: #include <iostream> #include <cstdio> #include <string> #include <vector> #include <cstring> #include <iterator> #in

HDU 5944 Fxx and string(水题)

传送门 Fxx and string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Submission(s): 1007    Accepted Submission(s): 422 Description Problem DescriptionYoung theoretical computer scientist Fxx get a string which