• HDU 5311 Hidden String


    Hidden String


    Problem Description
    Today is the 1st anniversary of BestCoder. Soda, the contest manager, gets a string s of length n. He wants to find three nonoverlapping substrings s[l1..r1], s[l2..r2], s[l3..r3] that:

    1. 1≤l1≤r1<l2≤r2<l3≤r3≤n

    2. The concatenation of s[l1..r1], s[l2..r2], s[l3..r3] is "anniversary".
     

    Input
    There are multiple test cases. The first line of input contains an integer T (1≤T≤100), indicating the number of test cases. For each test case:

    There's a line containing a string s (1≤|s|≤100) consisting of lowercase English letters.
     

    Output
    For each test case, output "YES" (without the quotes) if Soda can find such thress substrings, otherwise output "NO" (without the quotes).
     

    Sample Input

    2
    annivddfdersewwefary
    nniversarya

     

    Sample Output

    YES
    NO

    #include<cstdio>
    #include<cstring>
    using namespace std;
    
    struct str
    {
        char s1[15];
        char s2[15];
        char s3[15];
    }S[200];
    
    bool check(char *s,str a)
    {
        char *p;
        char *p2=s;
        char *p1=strstr(s,a.s1);
        if(p1)
        {
            for(p=p2;p<=p1+strlen(a.s1)-1;p++)
            *p='#';
            p2=p1;
            p1=strstr(s,a.s2);
            if(p1)
            {
                for(p=p2;p<=p1+strlen(a.s2)-1;p++)
                *p='#';
                p2=p1;
                p1=strstr(s,a.s3);
                if(p1)
                return true;
            }
        }
        return false;
    }
    int main()
    {
        int i,j,k,o,t;
        char p[]="anniversary";
        char s[105];
        char temp[105];
        int cnt=0;
        for(i=0;i<9;i++)
        for(j=i+1;j<10;j++)
        {
            for(o=t=0;t<=i;t++)
            S[cnt].s1[o++]=p[t];
            for(o=0;t<=j;t++)
            S[cnt].s2[o++]=p[t];
            for(o=0;t<11;t++)
            S[cnt].s3[o++]=p[t];
            cnt++;
        }
        scanf("%d",&t);
        while(t--)
        {
            scanf("%s",s);
            for(i=0;i<cnt;i++)
            {
                strcpy(temp,s);
                bool flag=check(temp,S[i]);
                if(flag)break;
            }
            if(i!=cnt)
            printf("YES
    ");
            else
            printf("NO
    ");
        }
        return 0;
    }
  • 相关阅读:
    HTML常用标签(自用,可能不严谨,勿怪)
    Nginx负载均衡和反向代理设置
    Django的列表反序
    Python装饰器通用样式
    WCF、Web API、WCF REST、Web Service的区别
    C++11 标准新特性: 右值引用与转移语义
    在windows下vs使用pthread
    部分浏览器记住密码后可能会带来的问题
    SQL Server、 My SQL、PG Sql、Oracle、 Access 不同数据库sql差异
    sql中select语句的逻辑执行顺序
  • 原文地址:https://www.cnblogs.com/homura/p/4748988.html
Copyright © 2020-2023  润新知