#2WA #4#5 MLE求调(玄关)
查看原帖
#2WA #4#5 MLE求调(玄关)
1144893
Kenneth1楼主2024/12/15 21:19

救命


代码如下

#include <bits/stdc++.h>
using namespace std;
string a,b;
string aa[10],bb[10];
queue <string> q;
queue <int> q1;
int end1,cnt=1;
void www(string aaa,int bu){
	if(bu>=9){
		cout<<"NO ANSWER!";
		end1=-1;
	}
	for(int i=1;i<=cnt;i++){
		if(end1==-1){
			break;
		}
		int h=0;
		string u=aaa;
		while(u.find(aa[i])!=-1){
			int y=u.find(aa[i],h);
			u.replace(y+u.begin(),y+aa[i].size()+u.begin(),bb[i]);
			if(u==b){
				end1=-1;
				cout<<bu+1;
				break;
			}
			q.push(u);
			q1.push(bu+1);
		}
	}
}
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>a>>b;
	while(cin>>aa[cnt]>>bb[cnt]){
		cnt++;
	}
	cnt--;
	if(a==b){
		cout<<0;
		return 0;
	}else{
		www(a,0);
	}
	while(!q1.empty()&&end1==0){
		www(q.front(),q1.front());
		q.pop();
		q1.pop();
	}
	return 0;
}
2024/12/15 21:19
加载中...