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. legend3---Homestead常用操作代码

    legend3---Homestead常用操作代码 一.总结 一句话总结: 在虚拟机里面改变文件windows里面也会变,在windows里面改变虚拟机里面也会变,所以可以在windows里面编程或者 ...

  2. TiDB官方文档

    TiDB官方文档: https://github.com/pingcap/docs-cn TiDB 整体架构 TiDB 集群主要包括三个核心组件:TiDB Server,PD Server 和 TiK ...

  3. 数据结构和算法(Java版)快速学习(数组Array)

    Java数组 在Java中,数组是用来存放同一种数据类型的集合,注意只能存放同一种数据类型. 用类封装数组实现数据结构 数据结构必须具有以下基本功能: ①.如何插入一条新的数据项 ②.如何寻找某一特定 ...

  4. day64—ajax技术学习笔记

    转行学开发,代码100天——2018-05-19 Ajax技术学习笔记 AJAX = Asynchronous JavaScript and XML(异步的 JavaScript 和 XML).AJA ...

  5. robot framework UI自动化之登录

    前面已写环境的搭建,接下来就可以直接进行UI自动化的编写工作了 目录 1.准备工作 2.了解定位 3.一个登录案例 1.准备工作 第一步:需要使用chrome浏览器来测试,因此首先要有一个驱动,下载好 ...

  6. 性能测试工具之WebBench

    一.简介 WebBench是一款在Linux下使用非常简单的压力测试工具.它的原理是:WebBench首先fork出多个子进程,每个子进程都循环做web访问测试.子进程把访问的结果通过pipe告诉父进 ...

  7. zstack分配的虚拟机的dns设置

    环境: $ uname -a Linux 10-57-19-61 2.6.32-504.el6.x86_64 #1 SMP Wed Oct 15 04:27:16 UTC 2014 x86_64 x8 ...

  8. 转:【开源必备】常用git命令

    原文:https://zhuanlan.zhihu.com/p/25868120 [开源必备]常用git命令 [已重置]   如今在技术领域,码农们习惯了开源,也离不开免费开源的代码,轻松获取代码,不 ...

  9. Matlab——表达式 阵列与矩阵的创建

    表达式 指令过长: 如果一个指令过长可以在结尾加上... 下一行继续写指令即可 若不想每次都显示运算结果,只需在运算式最後加上分号(:)即可 注释 基本的算术运算有: 加 (+).减 (-).乘 (* ...

  10. PHP 对Memcache的使用实例

    <?php //连接Memcache$mem = new Memcache;$mem->connect("localhost", 11211) or die (&quo ...