Educational Codeforces Round 68 (Rated for Div. 2) C. From S To T (字符串处理)
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 (字符串处理)的更多相关文章
- Educational Codeforces Round 68 (Rated for Div. 2)---B
http://codeforces.com/contest/1194/problem/B /* */ # include <bits/stdc++.h> using namespace s ...
- Educational Codeforces Round 68 (Rated for Div. 2)补题
A. Remove a Progression 签到题,易知删去的为奇数,剩下的是正偶数数列. #include<iostream> using namespace std; int T; ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- Educational Codeforces Round 43 (Rated for Div. 2)
Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...
随机推荐
- mysql update语句与limit的结合使用
有时候有需要批量更新数据表中从多少行到多少行的某个字段的值 mysql的update语句只支持更新前多少行,不支持从某行到另一行,比如 UPDATE tb_name SET column_name=' ...
- legend3---2、网站的代码里面的/也是代表根目录
legend3---2.网站的代码里面的/也是代表根目录 一.总结 一句话总结: 不过这个根目录在public下面 1.mysql删除数据库命令? drop database <数据库名> ...
- leetcode-mid-math-371. Sum of Two Integers-NO-???
mycode: 没思路啊...二级制四则运算不熟悉... 参考: 既然不能使用加法和减法,那么就用位操作.下面以计算5+4的例子说明如何用位操作实现加法: 1. 用二进制表示两个加数,a=5=0101 ...
- 使用collection查询集合属性
介绍resultMap中使用collection查询集合属性 业务需求,查询部门中的多个人员 public class Department { private Integer id; private ...
- 解决Python print输出不换行没空格的问题
今天在做编程题的时候发现Python的print输出默认换行输出,并且输出后有空格. 题目要求输出 122 而我的输出是: 1 2 2 于是我百度查到取消print自动换行的方法:就是在print的值 ...
- AAAI 2019 分析
AAAI 2019 分析 Google Scholar 订阅 CoKE : Word Sense Induction Using Contextualized Knowledge Embeddings ...
- 四十二、python中异常
1.常用异常: AttributeError 试图访问一个对象没有的树形,比如foo.x,但是foo没有属性xIOError 输入/输出异常:基本上是无法打开文件ImportError 无法引入模块或 ...
- 用Vue来实现音乐播放器(四十):歌单详情页布局以及Vuex实现路由数据通讯
1.歌单详情页是推荐页面的二级路由页面 将推荐页面歌单的数据传到歌曲详情页面 利用vuex 1.首先在state下定义一个歌单对象 disc{} 2.在mutaions-types中 定义一个别名 ...
- 阶段3 1.Mybatis_03.自定义Mybatis框架_4.自定义mybatis的编码-解析XML的工具类介绍
导入xml操作的类和用到的相关包 创建util包,然后把提供好的XMLConfigBuilder.java文件复制3过来 复制过来,里面用到了很多dom4j的东西 打开pom.xml 输入depend ...
- Java ——扩展:内部类 匿名内部类 IO file 设计模式
内部类的拓展 定义类or方法内部的类 最外层的类只能使用public和默认修饰 class Demo { class A { } public static void main(String[] ar ...