#include<iostream>
#include<array>
#include<algorithm>
#include<string>
#include<map>
#include<queue>
#include<utility>
#define reg register
using namespace std;
using gg=long long;
array<string,6> from,to;
queue<pair<string,gg>> list;
map<string,gg> ans;
int main()
{
reg gg top=0,t=0;
reg string beg,res;
cin>>beg>>res;
while(cin>>from[top]>>to[top]) top++;
list.push(make_pair(beg,0));
ans.insert({beg,0});
while(!list.empty()&&ans.find(res)==ans.end())
{
while(list.front().second==t)
{
for(reg gg i=0;i<top;i++)
{
string tp=list.front().first;
gg len=0;
while(tp.find(from[i],len)!=string::npos)
{
len=tp.find(from[i],len);
tp.replace(len,from[i].size(),to[i]);
auto fid=ans.find(tp);
if(fid==ans.end())
{
ans.insert({tp,t+1});
list.push(make_pair(tp,t+1));
}
len+=to[i].size()+1;
}
}
list.pop();
}
t++;
}
if(ans.find(res)==ans.end())
{
cout<<"NO ANSWER!\n";
}
else
{
cout<<(*ans.find(res)).second<<'\n';
}
return 0;
}
我感jio我写的很对啊???