我知道问题了,此贴终。
by Eric12 @ 2022-08-29 21:47:02
$$\#3 \color{green}AC $$
code:
```cpp
#include <bits/stdc++.h>
using namespace std;
vector<string>v;
vector<string>u;
queue<string> q;
string sta;
string ans;
inline string kmp(string a,string b,string c) {
int t = 0;
if(a.size()==b.size())return a==b ? c : a;
while(t < (a.size()-b.size())) {
int idx = -1;
for(int i = t; i < t+b.size() ;++i)
if(a[i] != b[i-t]) {idx = i;break;}
if(idx==-1) {
for(int i = t;i<t+b.size();++i)a[i]=c[i-t];
break;
}
int i = idx;
while(a[i]!=b[idx-t])++i;
t=i;
}
return a;
}
inline int bfs() {
q.push(sta);
queue<int>q2;
while(q.size()) {
string x = q.front();
q.pop();
if(x==ans)return q2.front();
for(int i = 0; i < v.size();++i) {
string y = kmp(x,v[i],u[i]);
if(y!=x){
q.push(y);
q2.push(q2.front()+1);
cout<<y<<endl;
}
}
q2.pop();
}
return 0;
}
int main()
{
cin>>sta>>ans;
string x,y;
for(int i = 0; i < 6 ; ++i) {
v.push_back(x);
u.push_back(y);
}
int b = bfs();
if(b)cout<<b;
else cout<<"NO ANSWER!";
return 0;
}
```
by ___njr___ @ 2023-05-05 13:38:36