很可能你在查找的时候只查了一次,注意,子字符串可能出现了多次关键代码
while(dx != string::npos) {
int m = dx + s[i].first.size();
string q = t.substr(0, dx) + s[i].second + t.substr( m,t.size());
if (!ma.count(q)) {
ma[q] = ma[t] + 1;
w.push(q);
if (q == b) {
cout << ma[q];
return 1;
}
}
int u = dx;
dx = t.find(s[i].first, u + 1);
}