2015 Multi-University Training Contest 10 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): 792    Accepted Submission(s): 283

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

4abcatcatsdodoappleaapple

 

 

Sample Output

NoYesYesNo

 

题目大意:给定一个字符串,问是否能够通过在任意字符后插入不同的字符得到指定的新字符串(所有字符均为小写字母),需要注意的有:1,不能在首位插入。2,插入字符与插入位置前一字符不能相同。3,插入操作可以多次进行,但每次只能插入一个字符。

这道题容易陷入思维误区,比如,apple是否能够变为allpple,看到插入了两个相同的字l,容易认为这是NO。但是按照题意,这是可以实现的,因为两个l不是同时插入,而是分开插入在a之后的,这样是完全符合题意的。

根据上述规则,不难想到,字符串里的任意字符,其连续个数都是可以增加的,只要插入时将字符插入到相同字符的前面。字符连续是完全可以做到的,除了第一个字符,因为其前一位不能插入字符。

按照这个思路,只要判断改变后的字符串其第一种字母的连续个数是否增加,即可判断是YES or NO.


#include<iostream>
#include<string.h>
using namespace std;
char a[100005];
char b[100005];
int main()
{
    int t;
    scanf("%d", &t);
    while (t--)
    {
        int i, j;
        scanf("%s%*c", a);
        scanf("%s%*c", b);
        int len_a = strlen(a);
        int len_b = strlen(b);
        bool diyiwei = true;
        if (a[0] != b[0])
            printf("No\n");
        else if (strcmp(a,b)==0)
            printf("Yes\n");
        else
        {
            for (j = 1, i = 1; j < len_b; j++)
            {
                if (b[j] != b[j - 1])
                    diyiwei = false;
                if (a[i] == b[j])
                    ++i;
                else
                {
                    if (b[j] == b[j - 1] && diyiwei)
                    {
                        break;
                    }
                }
            }
            if (i == len_a&&!diyiwei)
                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、付费专栏及课程。

余额充值