码迷,mamicode.com
首页 > 其他好文 > 详细

codeforces 1029 A. Many Equal Substrings

时间:2018-09-01 12:15:32      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:style   bst   长度   for   mes   开始   最大的   string   nbsp   

题意:给一个串t,构造一个尽可能长度小字符串,使得这个字符串里有k个子串t

只需要找出最大的前缀和后缀相等的情况即可,刚开始忘记了strstrstrstr的这种情况,用substr方便一点

#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
    int n,t,k=0,i; cin>>n>>t>>s;
    for(i=0;i<n-1;i++) if(s.substr(0,i+1)==s.substr(n-i-1)) k=i+1;cout<<s;
    for(i=1;i<t;i++) cout<<s.substr(k);
}

 

codeforces 1029 A. Many Equal Substrings

标签:style   bst   长度   for   mes   开始   最大的   string   nbsp   

原文地址:https://www.cnblogs.com/Fy1999/p/9568866.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!