Codeforces Round #506 (Div. 3) A. Many Equal Substrings
题意:构建字符串,即复制字符串s,k次,如果后缀与前缀重复省略前缀
题解:kmp板子next数组应用
#include<bits/stdc++.h> using namespace std; string s; int nex[1000]; int n,k; void next_l() { int len=s.size(); nex[0]=-1; int i=0,j=-1; while(i<len) { if(j==-1||s[i]==s[j]) { i++; j++; nex[i]=j; } else j=nex[j]; } } int main() { int n,k; cin>>n>>k; cin>>s; cout<<s; next_l(); k-=1; while(k--) { for(int i=nex[n]; i<n; i++) cout<<s[i]; } }