#4 #8 T飞了,求大佬帮帮忙
查看原帖
#4 #8 T飞了,求大佬帮帮忙
68884
jiangyanheng楼主2020/10/6 22:54
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int N=1e6+234;
int next[N];
string s1,s2;
inline void del(int &lo,string &ori,int l,int t){
	//分别表示:串的原始长度,原始串,删除的结尾位置,删除的长度
	string a=ori.substr(0,l-t);
//	l++;
	string b=ori.substr(l);
	
	
	ori=a+b;
	lo-=t;
}
string in(){
	string s;
	char c=getchar();
	while(c<'a' || c>'z') c=getchar();
	while('a'<=c && c<='z') s+=c,c=getchar();
	return s;
}
void write(int l,string s){
	for(int i=0;i<l;i++){
		putchar(s[i]);
	}
}
int main(){
	s1=in();
	s2=in();
	int l1=s1.length();
	int l2=s2.length();
	register int j=0,k=-1;
	next[0]=-1;
	while(j<l2){
		if (k==-1 || s2[k]==s2[j]){
			k++;
			j++;
			next[j]=k;
		}
		else{
			k=next[k];
		}
	}
	j=0;
	for(register int i=0;i<l1;i++){
		while(j>0 && s1[i]!=s2[j]){
			j=next[j];
		}
		if (s1[i]==s2[j]) j++;
		if (j==l2){
			j=0;
//			system("pause");
//			printf("%d %d\n",i,l2);
			del(l1,s1,i+1,l2);
			i=max(0,i-(l2<<1)-2);
//			printf("%d\n",i);
		}
	}
	write(l1,s1);
}

register、inline、快读快写都用了,氧也吸了,还是1.2s。 这程序是不是真没救了?

2020/10/6 22:54
加载中...