String Transformation + CCPC2018-湖南全国邀请赛

Bobo has a string S=s1s2sn consists of letter `a`, `b` and `c`.
He can transform the string by inserting or deleting substrings `aa`, `bb` and `abab`.

Formally, A=uwv (`` '' denotes string concatenation) can be transformed into A=uv and vice versa where u, v are (possibly empty) strings and w{aa,bb,abab}.

Given the target string T=t1t2tm, determine if Bobo can transform the string S into T
.
Input The input consists of several test cases and is terminated by end-of-file.

The first line of each test case contains a string s1s2sn.
The second line contains a string t1t2tm.
Output For each test case, print `Yes` if Bobo can. Print `No` otherwise.

## Constraint

* 1n,m104
* s1,s2,,sn,t1,t2,,tm{a,b,c}
* The sum of n and m does not exceed 250,000.
Sample Input
ab
ba
ac
ca
a
ab
Sample Output
Yes
No
No


        
  
Hint
For the first sample, Bobo can transform as `ab => aababb => babb => ba`.
 
#define happy

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;

typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;


#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)

#define all(a) (a).begin(),(a).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define f first
#define s second

ll rd(){
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}

const int N=1e4+10;

char a[N],b[N];

int main(){
#ifdef happy
    freopen("in.txt","r",stdin);
#endif
    int n;
    while(~scanf("%s %s",a,b)){
        int len=strlen(a)-1;
        vector<int> aa,bb;
        int s,t;
        s=t=0;
        int aaa,bbb;
        aaa=bbb=0;
        rep(i,0,len){
            if(a[i]=='c'){
                aa.pb(s%2);
                aa.pb(t%2);
                s=t=0;
                aaa++;
            }else{
                if(a[i]=='a'){
                    s++;
                }else{
                    t++;
                }
            }
        }
        aa.pb(s%2);
        aa.pb(t%2);
        s=t=0;
        len=strlen(b)-1;
        rep(i,0,len){
            if(b[i]=='c'){
                bb.pb(s%2);
                bb.pb(t%2);
                s=t=0;
                bbb++;
            }else{
                if(b[i]=='a'){
                    s++;
                }else{
                    t++;
                }
            }
        }
        bb.pb(s%2);
        bb.pb(t%2);
        s=t=0;
        if(aaa!=bbb){
            puts("No");
            continue;
        }
        if(aa.size()!=bb.size()){
            puts("No");
            continue;
        }
        len=aa.size()-1;
        bool f=false;
        rep(i,0,len){
            if(aa[i]!=bb[i]){
                f=true;
                break;
            }
        }
        if(f){
            puts("No");
        }else puts("Yes");
    }
}


猜你喜欢

转载自blog.csdn.net/ujn20161222/article/details/80534510