求助,怎么只AC了一个点?
查看原帖
求助,怎么只AC了一个点?
481471
Eric12楼主2022/8/29 21:03
#include <iostream>
#include <string>
#include <queue>
using namespace std;
string a,b;
int i,index;
struct rule{
	string re;
	string pre;
}r[1001];
struct node{
	string str;
	int step;
};
void fakebfs()
{
	queue<node> q;
	q.push({a,0});
	while(!q.empty())
	{
		node x=q.front();
		if(x.str==b)
		{
			cout<<x.step<<endl;
			return;
		}
		for(i=1;i<index;i++)
		{
			int zancun=0,zc=x.str.find(r[i].re,zancun);
			while(zc!=string::npos)
			{
				node next;
				next.str=x.str;
				next.str.replace(zc,zc+r[i].re.size(),r[i].pre);
				next.step=x.step+1;
				q.push(next);
				zancun=zc+1;
				zc=x.str.find(r[i].re,zancun);
			}
		}
		q.pop();
	}
}
int main()
{
	cin>>a>>b;
	for(i=1;cin>>r[i].re>>r[i].pre;i++)
		;
	index=i;
	fakebfs();
	return 0;
}
2022/8/29 21:03
加载中...