zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    os 模块1
    除法
    python基础四(jsonossys andomstring模块、文件、函数)
    python基础三(集合、文件)
    linux下mysql安装
    linux下tomcat安装
    linux系统jdk安装
    python基础二(list,tuple元祖、dic字典,字符串)
    python基础一(安装、变量、循环、git)
    charles抓包
  • 原文地址:https://www.cnblogs.com/xxrlz/p/11188026.html
Copyright © 2011-2022 走看看