zoukankan      html  css  js  c++  java
  • 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(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
    /*
    坑点:
    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
    ");
        else printf("No
    ");
        }
        return 0;
    }
    

      

  • 相关阅读:
    使用Oracle ODP.NET 11g的.NET程序发布方法
    Client使用c#和odp.net连接server oracle
    打造百度网盘备份利器:自动备份Linux VPS文件和多线程下载百度网盘资源
    安装软件:/lib/ld-linux.so.2: bad ELF interpreter解决
    ArcSDE数据库连接(直连、服务连)与GT_Geometry存
    AE的Annotation学习摘记
    Samba简单配置--匿名用户共享资料可读可写的实现
    Sublime Text 2 使用心得
    ArcGIS Server启动服务报:ERROR: Unable to start Xvfb on any port in the range 6600
    [DataContract] 和[DataMember]
  • 原文地址:https://www.cnblogs.com/zero-begin/p/4661436.html
Copyright © 2011-2022 走看看