评测情况
题目入口
#include<bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
map<string ,string>w;
int t;
string a,b;
int ans = INF;
int k = 0;
void DFS (string now,int step)
{
if(step > k)
{
return ;
}
if(now == b)
{
ans = min(ans , step);
return ;
}
map<string ,string> :: iterator it;
string changed=now;
for(it = w.begin(); it != w.end(); it++)
{
int e = -1;
while(1)
{
e = changed.find(it->first , e + 1);
if(e == -1)break;
changed = now;
changed.erase(e , it->first.size());
changed.insert(e , it->second);
DFS(changed , step + 1);
}
}
return;
}
int main()
{
cin>>a>>b;
string x,y;
while(cin>>x>>y)
{
w[x]=y;
}
while(ans == INF)
{
k++;
if(k == 11)
{
cout<<"NO ANSWET!";
return 0;
}
DFS(a,0);
}
cout<<ans;
return 0;
}