-
Notifications
You must be signed in to change notification settings - Fork 411
/
Copy pathC_1697.cpp
55 lines (50 loc) · 1.06 KB
/
C_1697.cpp
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
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define frn(n) for(int i = 0; i<n; i++)
#define frni(n, k) for(int i = k; i<n; i++)
#define vctri vector<int>
#define vctrl vector<ll>
#define all(x) x.begin(), x.end()
void solve(){
int n; cin>>n;
string s, t; cin>>s>>t;
int sb = 0, tb = 0;
frn(n){
if(s[i] == 'b') sb++;
if(t[i] == 'b') tb++;
}
if(sb != tb){
cout<<"NO"<<endl;
return;
}
int one = 0, two = 0;
for(; one<n; one++){
if(s[one] == 'b'){
continue;
}
while(t[two] == 'b'){
two++;
}
if((s[one] != t[two]) || (s[one] == 'a' && one>two) || (s[one] == 'c' && one<two)){
cout<<"NO"<<endl;
return;
}
two++;
}
cout<<"YES"<<endl;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t; cin>>t;
while(t--){
solve();
}
return 0;
}