C. From S To T

time limit per test1 second

memory limit per test256 megabytes

inputstandard input

outputstandard output

You are given three strings s, t and p consisting of lowercase Latin letters. You may perform any number (possibly, zero) operations on these strings.

During each operation you choose any character from p, erase it from p and insert it into string s (you may insert this character anywhere you want: in the beginning of s, in the end or between any two consecutive characters).

For example, if p is aba, and s is de, then the following outcomes are possible (the character we erase from p and insert into s is highlighted):

aba → ba, de → ade;

aba → ba, de → dae;

aba → ba, de → dea;

aba → aa, de → bde;

aba → aa, de → dbe;

aba → aa, de → deb;

aba → ab, de → ade;

aba → ab, de → dae;

aba → ab, de → dea;

Your goal is to perform several (maybe zero) operations so that s becomes equal to t. Please determine whether it is possible.

Note that you have to answer q independent queries.

Input

The first line contains one integer q (1≤q≤100) — the number of queries. Each query is represented by three consecutive lines.

The first line of each query contains the string s (1≤|s|≤100) consisting of lowercase Latin letters.

The second line of each query contains the string t (1≤|t|≤100) consisting of lowercase Latin letters.

The third line of each query contains the string p (1≤|p|≤100) consisting of lowercase Latin letters.

Output

For each query print YES if it is possible to make s equal to t, and NO otherwise.

You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).

Example

inputCopy

4

ab

acxb

cax

a

aaaa

aaabbcc

a

aaaa

aabbcc

ab

baaa

aaaaa

outputCopy

YES

YES

NO

NO

Note

In the first test case there is the following sequence of operation:

s= ab, t= acxb, p= cax;

s= acb, t= acxb, p= ax;

s= acxb, t= acxb, p= a.

In the second test case there is the following sequence of operation:

s= a, t= aaaa, p= aaabbcc;

s= aa, t= aaaa, p= aabbcc;

s= aaa, t= aaaa, p= abbcc;

s= aaaa, t= aaaa, p= bbcc.

题意:

给你3个字符串s,t, p, 询问是否可以从p中取出一些字符插入到字符串s的任意位置,使其等于t ?

思路:



因为s字符串中字符的顺序是没法改变的,所以我们要检测一下s中的字符是否是t中都有的,而且顺序是否一致、

如果一致再根据字符的个数判断就可以了。具体见code

细节见代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define rt return
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define chu(x) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
ll powmod(ll a, ll b, ll MOD) {ll ans = 1; while (b) {if (b % 2)ans = ans * a % MOD; a = a * a % MOD; b /= 2;} return ans;}
inline void getInt(int* p);
const int maxn = 1000010;
const int inf = 0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
char s[1005];
char t[1005];
char p[1005];
int q;
int need[300];
int cnt[300];
int main()
{
// freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);
//freopen("D:\\common_text\code_stream\\out.txt","w",stdout);
gg(q);
while (q--)
{
MS0(cnt);
MS0(need);
scanf("%s", s + 1);
scanf("%s", t + 1);
scanf("%s", p + 1);
int slen = strlen(s + 1);
int tlen = strlen(t + 1);
int plen = strlen(p + 1);
if (slen + plen < tlen)
{
printf("NO\n");
} else
{
int num = 0;
int id = 1;
repd(i, 1, tlen)
{
if (t[i] == s[id])
{
id++;
num++;
}
}
if (num != slen)
{
printf("NO\n");
} else
{
repd(i, 1, tlen)
{
need[t[i]]++;
}
repd(i, 1, slen)
{
cnt[s[i]]++;
}
repd(i, 1, plen)
{
cnt[p[i]]++;
}
int isok = 1;
for (char i = 'a'; i <= 'z'; ++i)
{
if (need[i] > cnt[i])
{
isok = 0;
break;
}
}
if (isok)
{
printf("YES\n");
} else {
printf("NO\n");
} } }
} return 0;
} inline void getInt(int* p) {
char ch;
do {
ch = getchar();
} while (ch == ' ' || ch == '\n');
if (ch == '-') {
*p = -(getchar() - '0');
while ((ch = getchar()) >= '0' && ch <= '9') {
*p = *p * 10 - ch + '0';
}
}
else {
*p = ch - '0';
while ((ch = getchar()) >= '0' && ch <= '9') {
*p = *p * 10 + ch - '0';
}
}
}

最新文章

  1. GameObject.Instantiate(游戏体的实例化),角色的选择
  2. NEFU 2016省赛演练一 I题 (模拟题)
  3. NHibernate&#39;s inverse - what does it really mean?
  4. (转)HTML文档头部信息
  5. UBUNTU12.4 安装磊科无线网卡驱动
  6. Xcode修改项目名称教程
  7. JavaScript、jQuery、HTML5、Node.js实例大全-读书笔记1
  8. C#微信登录-手机网站APP应用
  9. ListControl一细节处理
  10. asp.net生成缩略图、文字图片水印
  11. 文本属性Attributes 初步
  12. 根据矩阵变化实现基于 HTML5 的 WebGL 3D 自动布局
  13. Python机器学习 (Python Machine Learning 中文版 PDF)
  14. RecyclerView的点击、滑动、拖动事件
  15. Django数据库,在原有表中添加新字段
  16. golang结构体、接口、反射
  17. MRJob 极速入门教程,使用Python玩转Hadoop
  18. 数据分析与挖掘 - R语言:贝叶斯分类算法(案例三)
  19. 解决caffe绘制训练过程的loss和accuracy曲线时候报错:paste: aux4.txt: 没有那个文件或目录 rm: 无法删除&quot;aux4.txt&quot;: 没有那个文件或目录
  20. 用webstorm开发前端项目前的一些配置

热门文章

  1. 02 body标签中的相关标签
  2. Cannot connect to the Docker daemon. Is &#39;docker daemon&#39; running on this host?
  3. MVC简易分页(Razor)
  4. 使用pycharm编写python乱码
  5. Vue开发调试神器 vue-devtools
  6. Linux_Rsync远程同步备份服务器
  7. node初始化配置no
  8. golang 标准库 sync.Map 中 nil 和 expunge 区别
  9. python数据分析入门(一)----安装pandas
  10. 万万没想到,Spring Boot 竟然这么耗内存!