希望在Str 中删掉 1个屏蔽词(一个屏蔽词可能出现多次)
求最后的串
栈+hash
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | #include <iostream> #include <cstring> using namespace std; const int N =1e6+3; #define int long long int bas=29,pow[N],h[N]; char a[N],b[N]; int n,m, st[N],hh; int f2( int l, int r){ return h[r]-h[l-1]*pow[r-l+1]; } signed main(){ int i,j; pow[0]=1; for (i=1;i<=1e6;i++) pow[i]=pow[i-1]*bas; cin>>a+1>>b+1; n=strlen(a+1),m=strlen(b+1); int vb= 0; for (i=1;i<=m;i++) vb =vb*bas+b[i]; for (i=1;i<=n;i++){ st[++hh]=a[i]; h[hh]=h[hh-1]*bas+a[i]; if (hh-m+1>=1&&f2(hh-m+1,hh)==vb) hh-=m; } for (i=1;i<=hh;i++) cout<< char (st[i]); } |
分类:
字符串
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!