萌新求助
查看原帖
萌新求助
224336
AFewSuns楼主2021/1/27 15:57

RT,一直WA

代码如下

#include<bits/stdc++.h>
using namespace std;
namespace my_std{
	#define ll long long
	#define bl bool
	bl ccc(ll a,ll b){
		return a>b;
	}
	ll my_pow(ll a,ll b,ll mod){
		ll res=1;
		if(!b) return 1;
		while(b){
			if(b&1) res=(res*a)%mod;
			a=(a*a)%mod;
			b>>=1;
		}
		return res;
	}
	ll qpow(ll a,ll b){
		ll res=1;
		if(!b) return 1;
		while(b){
			if(b&1) res*=a;
			a*=a;
			b>>=1;
		}
		return res;
	}
	#define db double
	#define pf printf
	#define pc putchar
	#define fr(i,x,y) for(register ll i=(x);i<=(y);i++)
	#define pfr(i,x,y) for(register ll i=(x);i>=(y);i--)
	#define go(u) for(ll i=head[u];i;i=e[i].nxt)
	#define enter pc('\n')
	#define space pc(' ')
	#define fir first
	#define sec second
	#define MP make_pair
	#define il inline
	#define sr(a,b,n) sort((a)+(b),(a)+(n)+(b))
	#define psr(a,b,n) sort((a)+(b),(a)+(n)+(b),ccc)
	#define maxinf 0xffffffff
	#define mininf -0xffffffff
	#define chs(a,b,c) (a)?(b):(c)
	#define random(x) rand()*rand()%(x)
	#define inv(a,mod) my_pow((a),(mod-2),(mod))
	il ll read(){
		ll sum=0,f=1;
		char ch=0;
		while(!isdigit(ch)){
			if(ch=='-') f=-1;
			ch=getchar();
		}
		while(isdigit(ch)){
			sum=sum*10+(ch^48);
			ch=getchar();
		}
		return sum*f;
	}
	il void write(ll x){
		if(x<0){
			x=-x;
			pc('-');
		}
		if(x>9) write(x/10);
		pc(x%10+'0');
	}
	il void writeln(ll x){
		write(x);
		enter;
	}
	il void writesp(ll x){
		write(x);
		space;
	}
}
using namespace my_std;
ll n,k,tmp,kmp[55],cnt=1;//cnt表示正在输出第几个重复的原字符串 
char c[55];
int main(){
//	freopen("1.in","r",stdin);
//	freopen("asd.out","w",stdout);
	n=read();
	k=read();
	fr(i,1,n) scanf(" %c",&c[i]);
	kmp[1]=0;
	fr(i,2,n){
		tmp=kmp[i-1];
		while((c[i]!=c[tmp+1])&&tmp) tmp=kmp[tmp];
		if(c[tmp+1]==c[i]) kmp[i]=tmp+1;
	}//kmp,应该没错 
	tmp=0;
	while(tmp<=n){
		tmp++;//循环原字符串输出的位置 
		if((tmp==(n-kmp[n]+1))&&(cnt<k)){//到了与下一个字符串拼接的地方就从头循环 
			cnt++;
			tmp=1;
		}
		cout<<c[tmp];
	}
}
/*
3 4
qwe
*/
2021/1/27 15:57
加载中...