Codeforces Round #568 (Div. 2)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).

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 (1≤n≤105) — 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
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

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<string>
#define ll long long
#define dd double
dd PI = acos(-1);
using namespace std;
int main() {
	ll n; cin >> n;
	while (n--) {
		string s1; cin >> s1;
		string s2; cin >> s2;
		ll sum2 = 0;
		ll flag = 0;
		for (ll i = 0; i < s1.size(); i++) {
			ll count = 0;
			ll sum1 = 1;
			char t = s1[i];
			for (ll ii = i + 1; ii < s1.size(); ii++) {
				if (t == s1[ii]) {
					sum1++;
					continue;
				}
				else {
					break;
				}
			}
			for (ll j = sum2; j < s2.size(); j++) {
				if (s2[j] == t) {
					count++;
				}
				else {
					break;
				}
			}
			if (count == 0) {
				flag = 1;
				break;
			}
			//cout << count << " " << sum1 << endl;
			if (count >= sum1) {
				i = i + sum1 - 1;
				sum2 = sum2 + count;
			}
			else {
				flag = 1;
				break;
			}
		}
		if (flag == 1) {
			cout << "NO" << endl;
		}
		else {
			if (sum2 != s2.size()) {
				cout << "NO" << endl;
			}
			else {
				cout << "YES" << endl;
			}
		}
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值