B - Email from Polycarp

Posted nonames

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 n

(1n105) — the number of pairs to check. Further input contains n

descriptions of pairs.

The first line of each description contains a single non-empty word s

consisting of lowercase Latin letters. The second line of the description contains a single non-empty word t 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 s

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

.

Output

Output n

lines. In the i-th line for the i-th pair of words s and t print YES if the word t could be printed by typing the word s

. Otherwise, print NO.

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

题意就是:键盘坏了(按一次出现多个相同字符),第一行是正确字符串 , 判断第二行字符是否是第一行字符串在坏的键盘上按出来的。
思路:将第一行字符串的移动独立出来。

#include <iostream>
#include <iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <set>
using namespace std;

int main()

    int n ;
    while(cin >> n)
    
        for(int i = 0 ; i < n ; i++)
        
            string a , b ;
            cin >> a >> b ;
            int len2 = b.length() ;
            int pow = 0 ;
            int flag = 1 , ans = 0;
            for(int i = 0 ; i < len2 ; i++)
            
                if(b[i] == a[pow])
                
                    pow++ ;
                
                else
                
                    if(i > 0 && b[i] == a[pow - 1])
                        continue ;
                    else
                    
                        flag = 0 ;
                        break ;
                    
                
            
            if(pow != a.length())
            
                flag = 0 ;
            
            if(flag == 0)
                cout << "NO" << endl ;
            else
                cout << "YES" << endl ;

        
    

    return 0;

 

 

以上是关于B - Email from Polycarp的主要内容,如果未能解决你的问题,请参考以下文章

Django 设置 - DEFAULT_FROM_EMAIL 的动态值

Django default_from_email 名称

email.message_from_string() 和 imaplib 添加 '<' '>'

sql 树状查询

python email.message_from_string() 解析问题

Django2.1.3 smtp 邮件 553报警