zoukankan      html  css  js  c++  java
  • hdu5414(2015多校10)--CRB and String(字符串匹配)

    题目链接:点击打开链接

    题目大意:有A。B两个字符串。如今有一种操作能够在A的随意一个字符x后面添加一个字符y(x。=y)。问能不能将A变为B。

    首先假设A能够变成B,那么A就一定是B的一个子序列,这个能够在O(n+m)的时间内算出。

    假设A是B的子序列之后,推断添加的字符中是不是含有不能添加的情况,我们仅仅须要推断B从開始的一段连续的同样的字符串。是不是在A的开头也存在。假设存在,那么就是能够由A转化成B的。


    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    using namespace std ;
    char s1[100010] , s2[100010] ;
    int main() {
        int t , i , j , l1 , l2 ;
        char ch ;
        //freopen("1009.in","r",stdin) ;
        //freopen("9.out","w",stdout) ;
        scanf("%d", &t) ;
        while( t-- ) {
            scanf("%s %s", s1, s2) ;
            l1 = strlen(s1) ;
            l2 = strlen(s2) ;
            i = j = 0 ;
            while( i < l1 && j < l2 ) {
                if( s1[i] == s2[j] ) {
                    i++ ; j++ ;
                }
                else
                    j++ ;
            }
            if( i < l1 ) {
                printf("No
    ") ;
                continue ;
            }
            for(j = 1 ; j < l2 ; j++)
                if( s2[j] != s2[j-1] ) break ;
            for(i = 0 ; i < j ; i++)
                if( s1[i] != s2[0] ) break ;
            if( i < j )
                printf("No
    ") ;
            else
                printf("Yes
    ") ;
        }
        return 0 ;
    }
    


  • 相关阅读:
    Indexed DB入门导学(1)
    移动端touch事件封装
    javascript实现仿微信抢红包
    NODE学习:利用nodeJS去抓网页的信息
    ajax跨域请求无法携带cookie的问题
    四则运算
    wc
    我的问题
    css3新增加的属性
    css知识点回顾(一)
  • 原文地址:https://www.cnblogs.com/gavanwanggw/p/7001213.html
Copyright © 2011-2022 走看看