zoukankan      html  css  js  c++  java
  • CRB and String

    CRB and String
    Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 543 Accepted Submission(s): 208

    Problem Description
    CRB has two strings s and t.
    In each step, CRB can select arbitrary character c of s and insert any character d (d ≠ c) just after it.
    CRB wants to convert s to t. But is it possible?

    Input
    There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case there are two strings s and t, one per line.
    1 ≤ T ≤ 105
    1 ≤ |s| ≤ |t| ≤ 105
    All strings consist only of lowercase English letters.
    The size of each input file will be less than 5MB.

    Output
    For each test case, output “Yes” if CRB can convert s to t, otherwise output “No”.

    Sample Input

    4
    a
    b
    cat
    cats
    do
    do
    apple
    aapple

    Sample Output

    No
    Yes
    Yes
    No

    Author
    KUT(DPRK)
    题意:给你两个字符串s和t,你可以在字符串s中任意选一个字符c,在该字符c后插入一个字符d(d!=c),问经过多次此操作,能否将字符串s转化成字符串t;
    思路:
    对于这两个字符串,要能够插入成功必须符合两个条件
    1:s是t的字串
    2:对于t前k个字符如果是相同的s的前k个字符也必须是相同的,否则无法插入(想想为什么??)
    只要符合上面的条件就都可以转化成功

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <queue>
    #include <map>
    #include <algorithm>
    #define INF 0x3f3f3f3f
    using namespace std;
    
    typedef unsigned long long LL;
    
    const int Max = 110000;
    
    char s[Max],t[Max];
    
    bool flag;
    
    int main()
    {
        int T;
        int i,j;
        scanf("%d",&T);
        while(T--)
        {
            scanf("%s",s);
            scanf("%s",t);
            flag=false;
            i=0,j=0;
            for(; t[i]!=''; i++)
            {
                if(!flag&&t[i]==t[0]&&s[j]!=t[i])
                {
                    break;
                }
                if(t[i]!=t[0])
                {
                    flag=true;
                }
                if(s[j]!=''&&t[i]==s[j])
                {
                    j++;
                }
            }
            if(t[i]==''&&s[j]=='')
            {
                printf("Yes
    ");
            }
            else
            {
                printf("No
    ");
            }
        }
        return 0;
    }
    
  • 相关阅读:
    关于.NET Reflector
    Windows Debugging之九
    在IA32如何将程序计数器的值放入到整数寄存器中?
    [陆续添加]计算机网络最最基础的基本概念
    ASCII表
    [翻译文章]我们是如何做到的: 提高SharePoint.Microsoft.com站点的性能
    Windows API是什么?
    寄存器使用惯例
    阅读笔记 了解ASP.NET底层架构 之一
    汇编程序中的返回值
  • 原文地址:https://www.cnblogs.com/juechen/p/5255958.html
Copyright © 2011-2022 走看看