zoukankan      html  css  js  c++  java
  • bestcoder 48# 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(T105), 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
    #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
    ",id);
            if(id==3) printf("Yes
    ");
            else printf("No
    ");
        }
    }
    


  • 相关阅读:
    用友U8 | 【存货管理】提示用户***正在记账,不允许并发。
    用友U8 | 怎么准确查找【采购入库单】、【采购发票】,对应的凭证号?
    用友U8 | 中途启用序列号管理,该怎么操作?
    Excel:提取身份证号中的性别
    给jupyter 添加代码自动补全功能
    SQL函数之:截断字符串
    解决Maven子项目提示 ‘parent.relativePath‘ of POM
    公共NTP资源汇总
    iperf3的使用
    ZeroTier的使用
  • 原文地址:https://www.cnblogs.com/jhcelue/p/7381160.html
Copyright © 2011-2022 走看看