蒟蒻求助,p1032广搜#5WA,玄关2。
查看原帖
蒟蒻求助,p1032广搜#5WA,玄关2。
946218
ForEly楼主2023/7/19 20:09
#include<bits/stdc++.h>
using namespace std;
struct st{
	string s1;
	int tot;
};
st cmp;
struct str{
	string s1,s2;
	int len;
}a[7];
string A,B,tmp;
int jsq=0;
int wz,wz1;
queue<st> q;
int main(){
	cin>>A>>B;
	int d=B.size()-1;
//	for(int i=0;i<=d;i++){
//		if(A[i]!=B[i]){
//			wz1=i;
//			break;
//		}				
//	}
//	cout<<wz1<<endl;
	while(cin>>tmp){
		a[++jsq].s1=tmp;
		a[jsq].len=tmp.size();
		cin>>tmp;
		a[jsq].s2=tmp;
	}
	cmp={A,0};
	//cout<<cmp.s1<<" "<<cmp.tot<<"\n";
	q.push(cmp);
	st now;
	//cout<<q.front().s1<<q.front().tot;
	while(!q.empty()){
		now=q.front();
		//cout<<now.s1<<" "<<now.tot<<endl;
		tmp=now.s1;
		wz=now.tot;
		//cout<<tmp<<" "<<wz<<endl;
		if(tmp==B) break;
		q.pop();
		if(wz>10){
			printf("NO ANSWER!");
			return 0;
		}
		for(int i=1;i<=jsq;i++){
			if(tmp.find(a[i].s1/*,wz1*/)!=string::npos){
				tmp.replace(tmp.find(a[i].s1/*,wz1*/),a[i].len,a[i].s2);
				wz++;
				//cout<<tmp<<endl;
				//cout<<tmp<<endl;
				cmp={tmp,wz};
				q.push(cmp);
//				wz1++;
			}
			else continue;	
		}
		
	}
	if(tmp!=B) printf("NO ANSWER!");
	else printf("%d",wz);
//	for(int i=1;i<=jsq;i++)
//		cout<<a[i].s1<<" "<<a[i].len<<" "<<a[i].s2<<endl; 
}
//abaaaba abcdaba
//a b
//b d
//d e
//e f
//f g
//g c

附#5测试数据,Orz

2023/7/19 20:09
加载中...