hdu 5414 CRB and String(2015 Multi-University Training Contest 10)

CRB and String

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


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)
 

Source
 


    解题思路:
        
       由于是在s串上进行操作,s必须包含在t串中,还有t串的第1个元素必须相等且连续出现的次数也必须小于等于
  
  s串的,其他的连续出现的就不需要考虑了,因为可以在连续出现之前一直添加,如样例4,可以在a后添加多少个
 
  p都没问题。


 代码:
 
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;
const int maxn=100000+100;
char s[maxn];
char ts[maxn];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%s%s",s,ts);
        int n1=strlen(s);
        int n2=strlen(ts);
        int cur=0;
        for(int i=0;i<n2;i++)
        {
            if(ts[i]==s[cur])
            cur++;
            if(cur==n1)
            break;
        }
        if(cur==n1)
        {
            int a1=1,a2=1;
            for(int j=1;j<n1;j++)
            {
                if(s[j]==s[0])
                a1++;
                else
                break;
            }
            for(int j=1;j<n2;j++)
            {
                if(ts[j]==ts[0])
                a2++;
                else
                break;
            }
            if(a2>a1||s[0]!=ts[0])
            printf("No\n");
            else
            printf("Yes\n");
        }
        else
        printf("No\n");
    }
    return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值