当前位置: 首页> 游戏> 手游 > P1032 [NOIP2002 提高组] 字串变换,仅代码

P1032 [NOIP2002 提高组] 字串变换,仅代码

时间:2025/7/9 14:34:51来源:https://blog.csdn.net/jiangdongzhen/article/details/141534172 浏览次数:0次

本喵今天累了,所以水一篇。
题目链接:link,请点击这里喵~

#include <stdio.h>
#include <ctype.h>
#include <algorithm>
#include <string>
#include <iostream>
#include <map>
#include <list>
#define lnt long long
#define inf 0x7fffffff
using namespace std;
int xx;char ff,chh;inline int read(){xx=ff=0;while(!isdigit(chh)){if(chh=='-'){ff=1;}chh=getchar();}while(isdigit(chh)){xx=(xx<<1)+(xx<<3)+chh-'0';chh=getchar();}return ff? -xx: xx;
}
const int N=50;
struct node{string x;int cnt;
};
map<string,bool> ys;
string to[N][2];
int main(){string a,b;list<node> q;cin>>a>>b;int m=0;while(cin>>to[m][0]>>to[m][1]){++m;}q.push_back({a,0});while(!q.empty()){node u=q.front();if(u.cnt>10){puts("NO ANSWER!");return 0;}if(u.x==b){printf("%d",u.cnt);return 0;}q.pop_front();string p=u.x;for(int i=0;i<m;++i){int e=0;while((e=u.x.find(to[i][0],e))!=string::npos){p=u.x;p.replace(e,to[i][0].length(),to[i][1]);++e;if(ys.find(p)!=ys.end()){continue;}ys[p]=1;q.push_back({p,u.cnt+1});}}}puts("NO ANSWER!");return 0;
}
关键字:P1032 [NOIP2002 提高组] 字串变换,仅代码

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: