forked from DionysiosB/CodeForces
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1697C-AwoosFavoriteProblem.cpp
More file actions
32 lines (24 loc) · 1006 Bytes
/
1697C-AwoosFavoriteProblem.cpp
File metadata and controls
32 lines (24 loc) · 1006 Bytes
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
#include <iostream>
#include <vector>
int main(){
std::ios_base::sync_with_stdio(false);
long t; std::cin >> t;
while(t--){
long n; std::cin >> n;
std::string s, t; std::cin >> s >> t;
std::string ss(""), tt("");
std::vector<long> sav, scv, tav, tcv;
for(long p = 0; p < n; p++){
if(s[p] != 'b'){ss += s[p];}
if(t[p] != 'b'){tt += t[p];}
if(s[p] == 'a'){sav.push_back(p);}
else if(s[p] == 'c'){scv.push_back(p);}
if(t[p] == 'a'){tav.push_back(p);}
else if(t[p] == 'c'){tcv.push_back(p);}
}
bool ans(ss == tt && sav.size() == tav.size() && scv.size() == tcv.size());
for(long p = 0; ans && p < sav.size(); p++){if(sav[p] > tav[p]){ans = false;}}
for(long p = 0; ans && p < scv.size(); p++){if(scv[p] < tcv[p]){ans = false;}}
std::cout << (ans ? "YES" : "NO") << std::endl;
}
}