献上我可爱的Code:
#include <bits/stdc++.h>
using namespace std;
string a,b,a1[7],b1[7];
int n=1;
struct node
{
string x;
int y;
};
queue<node> q;
void bfs()
{
q.push({a,0});
while(!q.empty())
{
node h=q.front();
if(h.y>10)
{
cout<<"NO ANSWER!";
return ;
}
for(int i=1;i<=n;i++)
{
int p=h.x.find(a1[i],0);
while(true)
{
if(p==-1)
break;
string c=h.x.replace(p,a1[i].size(),b1[i]);
q.push({c,h.y+1});
cout<<h.x<<" "<<h.y<<endl;
if(c==b)
{
cout<<h.y+1;
return ;
}
p=h.x.find(a1[i],p+1);
}
}
q.pop();
}
}
int main()
{
cin>>a>>b;
while(cin>>a1[n]>>b1[n])
n++;
n--;
bfs();
return 0;
}
调好给(第一个调好的)关注