我也是啊
by wzysky @ 2019-08-02 13:55:03
```cpp
#include <queue>
#include <cstring>
#include <iostream>
#include <stdlib.h>
using namespace std;
struct node
{
int cnt;
string s;
};
string a, b, ax[7], bx[7];
int n = 0;
queue <node> q;
void bfs()
{
node tp = q.front(), t;
if (tp.cnt > 10) return;
if (tp.s == b) {
cout << tp.cnt;
exit(0); }
for (int i = 0 ; i < n ; i++)
if (tp.s.find(ax[i]) != tp.s.npos) {
t.cnt = tp.cnt + 1, t.s = tp.s;
t.s.replace(t.s.find(ax[i]), ax[i].size(), bx[i]);
q.push(t); }
q.pop();
}
int main()
{
cin >> a >> b;
while (cin >> ax[n] >> bx[n]) n++;
node t;
t.cnt = 0, t.s = a;
q.push(t);
while (!q.empty())
bfs();
cout << "NO ANSWER!";
}
by wzysky @ 2019-08-02 13:55:41
@[20070418yao](/space/show?uid=195751)
------------
~~加个map变80分~~
by wzysky @ 2019-08-02 14:03:06