-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckSubsequence.cpp
More file actions
70 lines (57 loc) · 925 Bytes
/
checkSubsequence.cpp
File metadata and controls
70 lines (57 loc) · 925 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include<iostream>
#include<string>
using namespace std;
bool checkSubsequence(string a,string b,int n,int m){
if(n==0){
return true;
}
if(m==0){
return false;
}
if(a[n-1]==b[m-1]){
return checkSubsequence(a,b,n-1,m-1);
}
else{
return checkSubsequence(a,b,n,m-1);
}
}
void solve(){
string p,s,t;
cin>>s>>t>>p;
int ss[26]={0};
int tt[26]={0};
int pp[26]={0};
for(int i=0;i<s.length();i++){
ss[s[i]-'a']++;
}
for(int i=0;i<p.length();i++){
pp[p[i]-'a']++;
}
for(int i=0;i<t.length();i++){
tt[t[i]-'a']++;
}
if(!checkSubsequence(s,t,s.length(),t.length())){
cout<<"NO"<<endl;
return ;
}
for(int i=0;i<26;i++){
ss[i]=ss[i]+pp[i];
}
for(int i=0;i<26;i++){
if(ss[i]<tt[i]){
cout<<"NO"<<endl;
return;
}
}
cout<<"YES"<<endl;
return ;
}
int main(){
int q;
cin>>q;
for(int i=0;i<q;i++){
solve();
}
return 0;
}
//http://codeforces.com/contest/1194/problem/C