我的IDE不知道怎么弄的所有编译信息都不显示,所以没法贴错误信息,如果逻辑上有错误的话各位大佬不用管,只是想知道编译为什么出错(我感觉代码好像也没什么问题啊)
/*@Unreal414 版权所有!!!*/
#include <bits/stdc++.h>
using namespace std;
string a, b;
set <string> s;
map <string, int> step;
map <int, pair <string, string> > rules;
int solve() {
queue <string> q;
q.push(a);
s.insert(a);
step[a] = 0;
while (q.size()) {
string &now = q.front();
q.pop();
if (step[now] > 10) continue;
for (auto &e : rules) {
int index;
string next = now;
while ((index = next.find(e.first)) <= next.size())
next.replace(index, index + e.first/*这里编译出错*/.size(), e/*这里编译出错*/.second);
if (s.count(next)) continue;
step[next] = step[now] + 1;
s.insert(next);
if (next == b) return step[next];
q.push(next);
}
}
return -1;
}
int main() {
cin >> a >> b;
while (cin >> rules[rules.size()].first >> rules[rules.size() - 1].second) {}
int result = solve();
if (result == -1) {
cout << "NO ANSWER!";
return 0;
}
cout << result << "\n";
return 0;
}