QAQ
by s_r_f @ 2018-04-03 22:31:48
万能头文件,定义变量和函数重复,会出事。这符合了“re”运行时出错的原因
by 龟龟号捕捞船 @ 2018-04-04 10:13:22
同问。。。
by Willendless @ 2018-05-18 17:41:44
```
#include <bits/stdc++.h>
using namespace std;
const int maxn = 6+5;
struct state{ string s; int num; state(string k = "", int x = -1):s(k),num(x){} };;
state beg, lst;
struct Op{ string from, to; } op[maxn];
set<string> vis;
int n;
int main()
{
cin >> beg.s >> lst.s;
while(cin >> op[n].from >> op[n].to) n++;
queue<state> que;
que.push(beg);
while(!que.empty()) {
state cur = que.front();
que.pop();
cur.num++;
if(cur.num > 10) break;
if(cur.s == lst.s) { lst.num = cur.num; break; }
if(vis.count(cur.s)) continue;
vis.insert(cur.s);
for(int i = 0; i < n; i++) {
unsigned int p = cur.s.find(op[i].from);
while(p != string :: npos) {
string lft = cur.s.substr(0, p);
string rgt = cur.s.substr(p+op[i].from.size());
string next = lft + op[i].to + rgt;
que.push(state(next, cur.num));
p = cur.s.find(op[i].from, p+1);
}
}
}
if(lst.num < 0) cout << "NO ANSWER!" << endl;
else cout << lst.num << endl;
}
```
by Willendless @ 2018-05-18 17:44:33