You are given two strings ss and tt, both of length nn. Each character in both string is 'a', 'b' or 'c'.
In one move, you can perform one of the following actions:
You are allowed to perform an arbitrary amount of moves (possibly, zero). Can you change string ss to make it equal to string tt?
Input
The first line contains a single integer qq (1≤q≤1041≤q≤104) — the number of testcases.
The first line of each testcase contains a single integer nn (1≤n≤1051≤n≤105) — the length of strings ss and tt.
The second line contains string ss of length nn. Each character is 'a', 'b' or 'c'.
The third line contains string tt of length nn. Each character is 'a', 'b' or 'c'.
The sum of nn over all testcases doesn't exceed 105105.
Output
For each testcase, print "YES" if you can change string ss to make it equal to string tt by performing an arbitrary amount of moves (possibly, zero). Otherwise, print "NO".
Example
input
Copy
5 3 cab cab 1 a b 6 abbabc bbaacb 10 bcaabababc cbbababaac 2 ba ab
output
Copy
YES NO YES YES NOs
1,透过操作要求,找到一些相对不变的规则
2,读假题了,“ab”是个连续的字串,因此a只能相对后移,c只能相对的前移
3,代码是通过验证通过的,需要符合2,以及去掉b后的字符串要一致
- #include
- using namespace std;
- #define int long long
- #pragma GCC optimize(2)
- #pragma GCC optimize(3,"Ofast","inline")//
- const int maxj=3e5+100,mod=998244353;
- void solve(){//构造验证,a的位置只会后移,c的位置只会前移,a,c的个数各自相同
- int n;cin>>n;
- string s,t;
- cin>>s>>t;
- int cnt1=0,cnt2=0;
- int ct1=0,ct2=0;
- vector<int>a1,a2,c1,c2;
- string ss1="",ss2="";
- for(int i=0;i
- if(s[i]!='b') ss1+=s[i];
- if(t[i]!='b') ss2+=t[i];
- if(s[i]=='a') a1.emplace_back(i);
- if(s[i]=='c') c1.emplace_back(i);
- if(t[i]=='a') a2.emplace_back(i);
- if(t[i]=='c') c2.emplace_back(i);
- }
- if(ss1!=ss2){//a,c相对位置不变,abc,cba这个不做考虑
- cout<<"NO"<<'\n';
- return ;
- }
- bool k=0;
- for(int i=0;i
size();++i){ - if(a1[i]>a2[i]){
- cout<<"NO"<<'\n';
- return ;
- }
- }
- for(int i=0;i
size();++i){ - if(c1[i]
- cout<<"NO"<<'\n';
- return ;
- }
- }
- cout<<"YES"<<'\n';
- }
- int32_t main(){
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- int t;
- cin>>t;
- // t=1;
- while(t--)solve();
- return 0;
- }
-
相关阅读:
基于PaddlePaddle的工业表计数环境搭建
HMM隐马尔可夫模型用于序列标注
高性能网络编程 - 关于单台服务器并发TCP连接数理论值的讨论
JavaSE => 抽象类和接口
【typescript - tsc 编译后路径问题/路径别名问题】
TDSQL-C 真·秒级启停:连接断了,又没断
hdfs分布式文件系统 默认数据存放路径、及相关配置属性详细解析
算法-1.两数之和
五月最近一次面试,被阿里P8测开虐惨了...
【JS】复习和学习几个好用的js小知识
-
原文地址:https://blog.csdn.net/m0_63054077/article/details/125708352