HDU-5414 CRB and String

http://acm.hdu.edu.cn/showproblem.php?pid=5414

题意:给定字符串s和t,可以在s里面选一个字符c,然后任选一个字符d(d!=c)将d插入到c的后面,问能不能将s变为t。

分析:只要前面t串连续的字符==s字符串,而且保证s是t的子串。本来想不通s:aabaa,t:aabaaaa,后面四个a怎么插,后来才想明白,后面的a都可以插在b后面,就可以了。

CRB and String

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 676 Accepted Submission(s): 256


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 ≤ T105
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)
 

 

Source
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

char s[100005],t[100005];
int main()
{
    int r;
    scanf("%d",&r);
     getchar();
    while(r--)
    {
      int i,j;
       scanf("%s",s);
        scanf("%s",t);
        int len1=strlen(s);
        int len2=strlen(t);
          int flag=1;
        for(i=1;i<len2;i++)
          if(t[i]!=t[0])
               break;//找到t串的第一个不连续的位置
         for(j=0;j<i;j++)//看s的前i个子串是否连续
             if(s[j]!=t[j])
                {
                    flag=0;
                    break;
                }
                j=i;
         for(;j<len1;j++)
         {
           for(;i<len2;i++)
            {//找到下一个和s相等的地方
            if(t[i]==s[j])
                break;
            }
          if(i==len2)
              {
                  flag=0;
                  break ;//如果t找完了还没跳出证明s不是t的子串
              }
          i++;
        }
        if(s[0]!=t[0])
                flag=0;
        if(flag)
           printf("Yes\n");
         else
         printf("No\n");
         }
    return 0;
}

 

转载于:https://www.cnblogs.com/cancangood/p/4749815.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值