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';
}
}
}

Educational Codeforces Round 68 (Rated for Div. 2) C. From S To T (字符串处理)的更多相关文章

  1. Educational Codeforces Round 68 (Rated for Div. 2)---B

    http://codeforces.com/contest/1194/problem/B /* */ # include <bits/stdc++.h> using namespace s ...

  2. Educational Codeforces Round 68 (Rated for Div. 2)补题

    A. Remove a Progression 签到题,易知删去的为奇数,剩下的是正偶数数列. #include<iostream> using namespace std; int T; ...

  3. Educational Codeforces Round 68 (Rated for Div. 2) D. 1-2-K Game (博弈, sg函数,规律)

    D. 1-2-K Game time limit per test2 seconds memory limit per test256 megabytes inputstandard input ou ...

  4. Educational Codeforces Round 68 (Rated for Div. 2)D(SG函数打表,找规律)

    #include<bits/stdc++.h>using namespace std;int sg[1007];int main(){ int t; cin>>t; while ...

  5. Educational Codeforces Round 68 (Rated for Div. 2)-D. 1-2-K Game

    output standard output Alice and Bob play a game. There is a paper strip which is divided into n + 1 ...

  6. Educational Codeforces Round 68 (Rated for Div. 2)-C-From S To T

    You are given three strings ss, tt and pp consisting of lowercase Latin letters. You may perform any ...

  7. Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...

  8. Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...

  9. Educational Codeforces Round 43 (Rated for Div. 2)

    Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...

随机推荐

  1. ubuntu16虚拟机迁移/移动/复制后无法上网

    修改grub配置 如果没有网卡,需要配置 sudo vi /etc/default/grub 将 GRUB_CMDLINE_LINUX="" 修改为 GRUB_CMDLINE_LI ...

  2. Linux_Comand - Check disk space

    df -h du -sh Delete folder older than 30 days find /path -name "test-*" -type d -mtime +30 ...

  3. Git-Runoob:Git 安装配置

    ylbtech-Git-Runoob:Git 安装配置 1.返回顶部 1. Git 安装配置 在使用Git前我们需要先安装 Git.Git 目前支持 Linux/Unix.Solaris.Mac和 W ...

  4. 软件-客户端管理工具-SourceTree-帮助:免费Git客户端:sourcetree详细介绍

    ylbtech-软件-客户端管理工具-SourceTree-帮助:免费Git客户端:sourcetree详细介绍 1.返回顶部 1. 一.简介:一个用于Windows和Mac的免费Git客户端.Sou ...

  5. tf多值离散embedding方法

    https://www.jianshu.com/p/4a7525c018b2 注意:一个域下的多值情况,这里最终输出是直接给出来每个域的(多值)的embedding值,多个值的也只输出一个embedd ...

  6. Unity Audio Source Properties

    Audio Clip 音频剪辑 将播放声音的剪辑文件 Mute 静音 Bypass Effects 直通效果 应用音频源的快速“直通”过滤效果.一个简单的方法来打开/关闭所有特效 Output 产量  ...

  7. oracle expdp/impdp/可传输表空间

    oracle expdp/impdp/可传输表空间/及一些参数 Oracle data pump 导出操作能够将表.索引.约束.权限.PLSQL包.同义词等对象从数据库导出,并将它们保存在一种非文本格 ...

  8. Spring MVC 中RequestContextHolder获取request和response

    1.最简单方式:处理方法入参 例如: @RequestMapping("/test") @ResponseBody public void saveTest(HttpServlet ...

  9. js实现上传文件实时显示缩略图

    <input name="coverImage" onClick="" onchange="setImagePreview(this);&quo ...

  10. Linux 下创建静态库和动态库

    1.创建静态链接库 2.创建动态链接库