求助
查看原帖
求助
1272259
cgxd楼主2024/4/12 18:27

不知道哪有问题

#include<bits/stdc++.h>
using namespace std;
string a, b, s1, s2;
queue<pair<string, int>> q;
vector<pair<string, string>> v;
int cnt = 0;
int main(){
	cin >> a >> b;
	while(cin >> s1 >> s2){
		pair<string, string> p(s1, s2);
		v.push_back(p);
	}q.push(pair<string, int>(a, 0));
	while(q.size()){
		string s1 = q.front().first;
		int k = q.front().second + 1;
		for(pair<string, string> p: v){
			string s3(s1);
			int a1 = s1.find(p.first);
			cout << p.first << ' ' << a1 << ' ';
			if(a1 == -1)
				continue;
			string s2(s3.replace(a1, a1 + p.first.size() - 1, p.second));
			pair<string, int> p1(s2, k);
			q.push(p1);
			if(q.back().first == b){
				cout << k;
				return 0;
			}if(k > 10){
				cout << "NO ANSWER!";
				return 0;
			}cout << q.back().first << ' ' << q.back().second << '\n';
		}
		q.pop();
	}cout << "NO ANSWER!" << ' ';
	return 0;
}
2024/4/12 18:27
加载中...