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

转载于:https://www.cnblogs.com/xxrlz/p/11188026.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值