为什么自己测都是对交上去只有20分
查看原帖
为什么自己测都是对交上去只有20分
919607
JasonTesla楼主2024/7/9 21:15
#include<bits/stdc++.h>
#include<map>
using namespace std;
map<string,int> bo;
struct Queue{
	string h;
	int step;
}gc[40010];
string bh[80][2],c;
int main(){
	getline(cin,c);
	string s="",e="",gz="aa";
	for(int i=0;i<c.size();++i){
		if(c[i]!=' ')e+=c[i];
		if(c[i]==' '){
			s=e;e="";
		}
	}
	int t=0;
	while(gz!=""){
		getline(cin,gz);
		string gs="",ze="";
		for(int i=0;i<gz.size();++i){
			if(gz[i]!=' ')ze+=gz[i];
			if(gz[i]==' '){
				gs=ze;ze="";
			}
		}t++;
		bh[t][0]=gs;
		bh[t][1]=ze;
	}
	t--;
	int head=0,tail=1;bool yu=1; 
	gc[1].h=s;gc[1].step=0;
	while(head<tail){
		head++;
		int st=gc[head].step+1;
		if(st>10){
			cout<<"NO ANSWER!";return 0;
		}
		for(int i=1;i<=t;++i){	
			int sy=gc[head].h.find(bh[i][0],0);
			while(sy!=-1){
				int ens=sy+bh[i][0].size(),nm=sy;
				string zhh="";
				for(int j=0;j<sy;++j){
					zhh+=gc[head].h[j];
				}
				zhh+=bh[i][1];
				for(int j=ens;j<gc[head].h.size();++j){
					zhh+=gc[head].h[j];
				}
				if(bo[zhh]==0){
					tail++;
					gc[tail].h=zhh;gc[tail].step=st;
					//cout<<zhh<<" "<<st<<endl;
					if(zhh==e){
						cout<<st;yu=0;return 0;
					}
					bo[zhh]=1;
				}sy=gc[head].h.find(bh[i][0],nm+1);
			} 
		}
	}if(yu)cout<<"NO ANSWER!";
return 0;}
2024/7/9 21:15
加载中...