Codeforces Round #568 (Div. 2 B - Email from Polycarp

B - Email from Polycarp
Methodius received an email from his friend Polycarp. However, Polycarp’s keyboard is broken, so pressing a key on it once may cause the corresponding symbol to appear more than once (if you press a key on a regular keyboard, it prints exactly one symbol).

For example, as a result of typing the word “hello”, the following words could be printed: “hello”, “hhhhello”, “hheeeellllooo”, but the following could not be printed: “hell”, “helo”, “hhllllooo”.

Note, that when you press a key, the corresponding symbol must appear (possibly, more than once). The keyboard is broken in a random manner, it means that pressing the same key you can get the different number of letters in the result.

For each word in the letter, Methodius has guessed what word Polycarp actually wanted to write, but he is not sure about it, so he asks you to help him.

You are given a list of pairs of words. For each pair, determine if the second word could be printed by typing the first one on Polycarp’s keyboard.

Input
The first line of the input contains one integer ? (1≤?≤105) — the number of pairs to check. Further input contains ? descriptions of pairs.

The first line of each description contains a single non-empty word ? consisting of lowercase Latin letters. The second line of the description contains a single non-empty word ? consisting of lowercase Latin letters. The lengths of both strings are not greater than 106.

It is guaranteed that the total length of all words ? in the input is not greater than 106. Also, it is guaranteed that the total length of all words ? in the input is not greater than 106.

Output
Output ? lines. In the ?-th line for the ?-th pair of words ? and ? print YES if the word ? could be printed by typing the word ?. Otherwise, print NO.

Examples
inputCopy
4
hello
hello
hello
helloo
hello
hlllloo
hello
helo
outputCopy
YES
YES
NO
NO
inputCopy
5
aa
bb
codeforces
codeforce
polycarp
poolycarpp
aaaa
aaaab
abcdefghijklmnopqrstuvwxyz
zabcdefghijklmnopqrstuvwxyz
outputCopy
NO
NO
YES
NO
NO

题目:https://codeforces.com/contest/1185/problem/B
题意:当您按某个键时,必须出现相应的符号(可能不止一次)。键盘以随机方式断开,这意味着按下相同的键可以在结果中获得不同数量的字母。说明第二个字符串首先要保证比第一个长,比较两个字符串可以用指针思想,记第一个为a字符串,第二个为b字符串,如果a,b元素相同,则指针++,指向下一个元素。如果a,b中元素不同,但是b字符串中相邻字符相同,则接着执行,否则直接跳出。
AC代码:

#include< iostream>
#include< cstdio>
#include< cstring>
#include< algorithm>
#define rep(i,a,b)for(int i=a;i<=b;i++)
using namespace std;
const int maxn=1e6+5;
char a[maxn],b[maxn];
int main(){
    int n;
    scanf("%d",&n);
    while(n--){
        scanf("%s%s",a,b);
        int len=strlen(b);
        int pos=0;
        int flag=1;
        rep(i,0,len-1){
            if(b[i]==a[pos]){
                pos++;
                //printf("%d\n",pos);
            }
            else{
                if(i>0&&b[i]==b[i-1])continue;//此时不能用b[i+1]==b[i]
                else{
                    flag=0;
                    break;
                }
            }
        }
        if(pos!=strlen(a))flag=0;
        if(flag)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、付费专栏及课程。

余额充值