C. From S To T

 

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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

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

For example, if pp is aba, and ss is de, then the following outcomes are possible (the character we erase from pp and insert into ss 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 ss becomes equal to tt. Please determine whether it is possible.

Note that you have to answer qq independent queries.

Input

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

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

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

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

Output

For each query print YES if it is possible to make ss equal to tt, 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

input

Copy

4
ab
acxb
cax
a
aaaa
aaabbcc
a
aaaa
aabbcc
ab
baaa
aaaaa

output

Copy

YES
YES
NO
NO

Note

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

  1. s=s= ab, t=t= acxb, p=p= cax;
  2. s=s= acb, t=t= acxb, p=p= ax;
  3. s=s= acxb, t=t= acxb, p=p= a.

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

  1. s=s= a, t=t= aaaa, p=p= aaabbcc;
  2. s=s= aa, t=t= aaaa, p=p= aabbcc;
  3. s=s= aaa, t=t= aaaa, p=p= abbcc;
  4. s=s= aaaa, t=t= aaaa, p=p= bbcc.

 

 

 

题意:三个字符串s t p,能否将p中的字符放入s中,使其成为t

思路:进行两次判断,1.s是t的字串,2.p中的字符可以补全s,使其成为t

代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<set>
#include<map>
#pragma warning(disable:4996)
using namespace std;
const int maxn = 10005;
string s, t, p;
map<char, int>q;
bool check(string s, string t) {//判断s是否是t的子串
	int j = 0;
	for (int i = 0; i < t.length(); i++) {
		for (j; j < s.length(); j++) {
			if (t[i] == s[j]) {
				j++;
				break;
			}
			else {
				break;
			}
		}
	}
	if (j == s.length()) {
		return 1;
	}
	else {
		return 0;
	}
}
int main() {
	int t1;
	scanf("%d", &t1);
	while (t1--) {
		cin >> s >> t >> p;
		bool flag = false;
		if (check(s, t)) {
			q.clear();
			for (int i = 0; i < t.length(); i++) {
				q[t[i]]++;
			}
			for (int i = 0; i < s.length(); i++) {
				q[s[i]]--;
			}
			for (int i = 0; i < p.length(); i++) {
				if (q[p[i]] > 0) {
					q[p[i]]--;
				}
			}
			for (int i = 0; i < t.length(); i++) {
				if (q[t[i]] > 0) {
					flag = true;
					break;
				}
			}
		}
		else {
			flag = true;
		}
		if (flag == true) {
			printf("NO\n");
		}
		else {
			printf("YES\n");
		}
	}
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值