Educational Codeforces Round 68 (Rated for Div. 2) C
- 题目大意: 给出字符串\(s,t,p\),可以从\(p\)中任意取字符加入\(s\)中,问经过某些操作能否将\(p\)变成\(s\)
- 思路: 因为\(s,t\)中字符的相对位置不可以改变,从前到后对\(t\)用\(s\)当前首位或\(p\)中任意一位对其进行匹配,贪心先用\(s\)的首位匹配. 如果匹配完成且\(t\)完全使用则可以匹配.
#include<cstdio>
#include<cstring>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
#include<map>
#define ll long long
#define FOR(i,n) for(int i =1; i <= n;++i )
#define FOR0(i,n) for(int i =0; i < n;++i )
#define ALL(ve) ve.begin(),ve.end()
#define inf 0x3f3f3f3f
using namespace std;
int T;
deque<char> s;
deque<char> t;
int cntCh[28];
int main(){
cin >> T;
while(T--){
memset(cntCh,0,sizeof(cntCh));
s.clear();
t.clear();
string buf;
cin >> buf;
for(int i=0;i<buf.size();++i){
s.push_back(buf[i]);
}
cin >> buf;
for(int i=0;i<buf.size();++i){
t.push_back(buf[i]);
}
cin >> buf;
for(int i=0;i<buf.size();++i){
cntCh[buf[i]-'a']++;
}
while(!t.empty()){
char ch = t.front();
t.pop_front();
if(s.empty()){
if(cntCh[ch-'a']==0){
s.push_back('z');
break;
}else{
cntCh[ch-'a']--;
}
}else if(s.front()!=ch){
if(cntCh[ch-'a']==0){
break;
}else{
cntCh[ch-'a']--;
}
}else{
s.pop_front();
}
}
if(!s.empty()){
cout <<"NO" <<endl;
}else{
cout <<"YES" <<endl;
}
}
}
现在菜到只会写C了TAT