%%大佬爆切双向bfs
by xhQYm @ 2020-02-11 12:27:07
```cpp
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <vector>
#include <list>
#include <set>
#include <functional>
#include <fstream>
#include <iomanip>
#include <cstdlib>
#include <cctype>
#include <ctime>
#include <sstream>
using namespace std;
map <string , int > mp;
int main()
{
string a,b;
cin >> a >> b;
string x[10],y[10];
int n = 1;
while(cin >> x[n] >> y[n])
{
n++;
}
n--;
queue < string > q;
queue <int > s;
q.push(a);
s.push(0);
while(!q.empty())
{
if(q.front() == b)
{
printf("%d",s.front());
return 0;
}
if(s.front() == 10)
{
q.pop();
s.pop();
}
string l = q.front();
if(mp.count(l))
{
q.pop();
s.pop();
continue;
}
mp[l] = 1;
for(int i = 1;i <= n;i++)
{
int p = 0;
while(l.find(x[i],p) != -1)
{
p = l.find(x[i],p);
q.push(l.substr(0,p) + y[i] + l.substr(p + x[i].length()));
s.push(s.front() + 1);
p++;
}
}
q.pop();
s.pop();
}
printf("NO ANSWER!");
return 0;
}
by qrhao @ 2020-02-11 16:54:00
我找着哪里错了..一个该写while的地方写成了if...
by Light_Cone @ 2020-02-11 17:50:38
现在还有用```exit(0);```的人那
by JRzyh @ 2020-02-28 10:18:30
@[Zhaoyuhang2008](/user/242524) 请问```exit(0);```是有什么漏洞吗?..
by Light_Cone @ 2020-03-01 15:28:46