求助dalao,80pts,第5点wa

P1032 [NOIP2002 提高组] 字串变换

我MLE ``` #include <bits/stdc++.h> using namespace std; struct node { string s; int st; }; queue <node> q; int n = 1; string a, b, s1[10], s2[10]; int main () { // string t1 = "abc", t2 = "a"; // cout << t1.find (t2); cin >> a >> b; while (cin >> s1[n] >> s2[n]) n++; q.push (node {a, 0}); while (!q.empty ()) { string s = q.front ().s; int tst = q.front ().st; q.pop (); if (s == b) { cout << tst; return 0; } if (tst > 10) continue; for (int i = 1; i <= n; i++) { int l = s.find (s1[i]); if (l != -1) { string tmp = s; tmp.erase (l, s1[i].length ()); tmp.insert (l, s2[i]); q.push (node {tmp, tst + 1}); } } } cout << "NO ANSWER!"; return 0; } ```
by qiutianqwq @ 2022-05-15 14:19:34


|