hdu 5414 CRB and String(字符串模拟)

CRB and String

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


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
题意:有两个串s和t,问能不能通过往s串里多次插入字符从而使s串变成t串,注意插入的字符不能和插入位置的前一个字符相同。比如abc和aabc就是不合法的

思路:直接模拟便是。 注意abc和abbbbbbbbbbc是合法的,因为可以在a后面多次插入b

代码:

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
#define N 100005
char s[N],t[N];
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%s %s",s,t);
        int lens=strlen(s),lent=strlen(t),nt=1;
        int flag=0;
        if(s[0]!=t[0]) flag=1;
        else
        {
            for(int i=1; i<lens; )
            {
                if(s[i]==t[nt])
                {
                    i++;
                    nt++;
                    continue;
                }
                int now=nt-1;
                while(t[now]==t[nt]) now--;
                if(now==-1)
                {
                    flag=1;
                    break;
                }
                nt++;
                if(nt>=lent)
                {
                    flag=1;
                    break;
                }
            }
            for(int i=nt; i<lent; i++)
            {
                if(t[i]==t[i-1])
                {
                    int now=nt-1;
                    while(t[now]==t[nt]) now--;
                    if(now==-1)
                    {
                        flag=1;
                        break;
                    }
                }
            }
        }
        if(flag) printf("No\n");
            else printf("Yes\n");
    }
    return 0;
}



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值