比较水的模拟
思路:就是模拟题意
注意:把数组开大点,开始wa了几次就是这个原因
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
string a, b;
int aa[], t, n;
bool flag1; int main(){
cin>>n;
cin>>a>>b;
int p=, q=;
while(q<n){
bool flag=;
while(q<n&&a[p]==b[q]){++p; ++q;}
while(p<n&&a[p]!=b[q]){++p; flag=;}
if(flag&&p==n){flag1=; break;}
for(int i=p;i>q;--i){
swap(a[i], a[i-]); aa[t++]=i;
}
p=q;
}
if(flag1)cout<<-<<endl;
else {
cout<<t<<endl;
for(int i=;i<t;++i)
cout<<aa[i]<<" ";
cout<<endl;
} }