Codeforces Round #568 (Div. 2)B
B. Email from Polycarp
题目链接:http://codeforces.com/contest/1185/problem/B
题目:
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 (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
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<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int maxn=1e6+;
struct node{
char str;
int num;
}node[maxn],node1[maxn];
int main()
{
int n;
scanf("%d",&n);
char str[maxn],str1[maxn];
while(n--)
{
scanf("%s%s",str,str1);
int num=strlen(str);
int num1=strlen(str1);
int book=,book1=;
for(int i=;i<max(num,num1);i++)
{
node[i].num=;
node1[i].num=;
}
node[].str=str[];
node1[].str=str1[];
node[].num=;
node1[].num=;
for(int i=;i<num;i++)
{
if(str[i]==str[i-])
{
node[book].num++;
node[book].str = str[i];
}
else
{
book++;
node[book].num++;
node[book].str=str[i];
} }
for(int i=;i<num1;i++)
{
if(str1[i]==str1[i-])
{
node1[book1].num++;
node1[book1].str = str1[i];
}
else
{
book1++;
node1[book1].num++;
node1[book1].str=str1[i];
}
}
int sum=unique(str,str+num)-str;
int sum1=unique(str1,str1+num1)-str1;
if(num>num1)
puts("NO");
else if(sum!=sum1)
puts("NO");
else { bool flag = true;
for (int i = ; i < sum; i++) {
if (node[i].str != node1[i].str || node[i].num > node1[i].num) {
flag = false;
break;
} }
if (flag)
puts("YES");
else
puts("NO");
} } return ;
}
/*
4
polycarp
poolycarpp */
Codeforces Round #568 (Div. 2)B的更多相关文章
- Codeforces Round #568 (Div. 2)A
A. Ropewalkers 题目链接:http://codeforces.com/contest/1185/problem/A 题目: Polycarp decided to relax on hi ...
- codeforces Round #568(Div.2)A B C
有点菜,只写出了三道.活不多说,上题开干. A. Ropewalkers Polycarp decided to relax on his weekend and visited to the per ...
- Codeforces Round #568 (Div. 2) D. Extra Element
链接: https://codeforces.com/contest/1185/problem/D 题意: A sequence a1,a2,-,ak is called an arithmetic ...
- Codeforces Round #568 (Div. 2) C2. Exam in BerSU (hard version)
链接: https://codeforces.com/contest/1185/problem/C2 题意: The only difference between easy and hard ver ...
- Codeforces Round #568 (Div. 2) B. Email from Polycarp
链接: https://codeforces.com/contest/1185/problem/B 题意: Methodius received an email from his friend Po ...
- Codeforces Round #568 (Div. 2) A.Ropewalkers
链接: https://codeforces.com/contest/1185/problem/A 题意: Polycarp decided to relax on his weekend and v ...
- Codeforces Round #568 (Div. 2) G1. Playlist for Polycarp (easy version) (状压dp)
题目:http://codeforces.com/contest/1185/problem/G1 题意:给你n给选项,每个选项有个类型和价值,让你选择一个序列,价值和为m,要求连续的不能有两个相同的类 ...
- Codeforces Round #568 Div. 2
没有找到这场div3被改成div2的理由. A:签到. #include<bits/stdc++.h> using namespace std; #define ll long long ...
- Codeforces Round #568 (Div. 2) G2. Playlist for Polycarp (hard version)
因为不会打公式,随意就先将就一下? #include<cstdio> #include<algorithm> #include<iostream> #include ...
随机推荐
- Qt5.4.1在windows7配置Android开发环境(阳光柠檬_)
网上的说法有些时间比较久远,软件更新又快,配置路上总有一些坎坷. 自己亲自尝试了一遍,记录下来. 所需的软件: 1. qt-opensource-windows-x86-android-5.4.1.e ...
- WPF实现选项卡效果(3)——自定义动态添加的AvalonDock选项卡内容
原文:WPF实现选项卡效果(3)--自定义动态添加的AvalonDock选项卡内容 简介 在前面一篇文章里面,我们实现了AvalonDock选项卡的动态添加,但是对于选项卡里面的内容,我们并没有实现任 ...
- jquery li练习2-恢复链条
<!DOCTYPE html><html lang="en" xmlns="http://www.w3.org/1999/xhtml"> ...
- js 动态操作元素
<!DOCTYPE html><html lang="en" xmlns="http://www.w3.org/1999/xhtml"> ...
- c# 全局钩子实现扫码枪获取信息。
原文:c# 全局钩子实现扫码枪获取信息. 1.扫描枪获取数据原理基本相当于键盘数据,获取扫描枪扫描出来的数据,一般分为两种实现方式. a)文本框输入获取焦点,扫描后自动显示在文本框内. b)使用键盘钩 ...
- 【全面解禁!真正的Expression Blend实战开发技巧】第九章 FluidMoveBehavior完全解析之二平滑运动的滚动条
原文:[全面解禁!真正的Expression Blend实战开发技巧]第九章 FluidMoveBehavior完全解析之二平滑运动的滚动条 这一章讲解FluidMoveBehavior的另一个应用, ...
- TLD单目标跟踪算法程序详解--OpenTLD Code 详解
TLD算法原理介绍:http://www.cnblogs.com/liuyihai/p/8306419.html OpenTLD源代码页: https://github.com/zk00006/Ope ...
- codewars杂记: 寻找缺失的数
题目描述: 给出一个整数列表,找出该列表无法通过各种组合求和得到的最小的整数. 示例: solve([1,2,8,7]) = 4, because we can get 1, 2, 1+2=3. Bu ...
- Mac OS启动服务优化高级篇(launchd tuning)禁用某些服务
http://kenwublog.com/mac-os-launchd-tuning Mac下的启动服务主要有三个地方可配置:1,系统偏好设置->帐户->登陆项2,/System/Libr ...
- 微信小程序把玩(四十)animation API
原文:微信小程序把玩(四十)animation API 动画水还是比较深的,这里只是简单介绍下小程序中动画的一些属性和注意事项,做动画前一定要整理好思路将动画一步步分解,再进行组合!这里只做引入. w ...