救命
代码如下
#include <bits/stdc++.h>
using namespace std;
string a,b;
string aa[10],bb[10];
queue <string> q;
queue <int> q1;
int end1,cnt=1;
void www(string aaa,int bu){
if(bu>=9){
cout<<"NO ANSWER!";
end1=-1;
}
for(int i=1;i<=cnt;i++){
if(end1==-1){
break;
}
int h=0;
string u=aaa;
while(u.find(aa[i])!=-1){
int y=u.find(aa[i],h);
u.replace(y+u.begin(),y+aa[i].size()+u.begin(),bb[i]);
if(u==b){
end1=-1;
cout<<bu+1;
break;
}
q.push(u);
q1.push(bu+1);
}
}
}
int main(){
cin>>a>>b;
while(cin>>aa[cnt]>>bb[cnt]){
cnt++;
}
cnt--;
if(a==b){
cout<<0;
return 0;
}else{
www(a,0);
}
while(!q1.empty()&&end1==0){
www(q.front(),q1.front());
q.pop();
q1.pop();
}
return 0;
}