A. Many Equal Substrings

You are given a string tt consisting of nn lowercase Latin letters and an integer number kk .

Let's define a substring of some string ss with indices from l to r as s[l…r]s[l…r] .

Your task is to construct such string ss of minimum possible length that there are exactly k positions i such that s[i…i+n−1]=ts[i…i+n−1]=t . In other words, your task is to construct such string ss of minimum possible length that there are exactly kk substrings of ss equal to t .

It is guaranteed that the answer is always unique.

Input

The first line of the input contains two integers n and k (1≤n,k≤501≤n,k≤50 ) — the length of the string t and the number of substrings.

The second line of the input contains the string t consisting of exactly n lowercase Latin letters.

Output

Print such string ss of minimum possible length that there are exactly k substrings of ss equal to t .

It is guaranteed that the answer is always unique.

Examples

Input

Copy

3 4
aba

Output

Copy

ababababa

Input

Copy

3 2
cat

Output

Copy

catcat

很明显这是一个字符串的处理问题,要用到substr来截取字符串,但有可能在一个字符串中有重复的,所以要去重,用下标来索引。

#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>using namespace std;int main()
{int n, m;string s;cin >> n >> m >> s;int temp;for(int i = 0; i < n; i++) if(s.substr(0, i) == s.substr(n-i, i)) temp = i;for(int i = 1; i < m; i++) cout << s.substr(0, n - temp);cout << s << endl;return 0;
}

A. Many Equal Substrings(自己很水)相关推荐

  1. 通过KNN算法,确定球星的风格(很水)

    KNN算法,故名思议,K个最邻近值的分类算法.监督学习中的一种,典型的懒人算法,通过计算所有的预测样本到学习样本的距离,选取其中K个最小值加入样本组中,样本组中的样本隶属于那个分类的个数最多,那么我们 ...

  2. 为什么有些 985、211 的本科学生即使在大学里混得很水,在找工作时学历却那么管用?...

    学术分享,侵删 知乎:https://www.zhihu.com/question/354234322 编辑:AI有道 最近网上有个话题比较有争议:[为什么有些 985.211 的本科学生即使在大学里 ...

  3. 为什么有些 985 的本科学生即使在大学里混得很水,在找工作时学历却那么管用?...

    大家好,我是老赵 最近网上有个话题比较有争议:「为什么有些 985.211 的本科学生即使在大学里混得很水,在找工作时学历却那么管用?」考上了重点大学,就真的能够高枕无忧了吗?让我们一起来了解一下吧. ...

  4. 科研有很水的idea应该发表出来吗?

    点击上方"小白学视觉",选择加"星标"或"置顶" 重磅干货,第一时间送达 本文转自|AI算法与图像处理 作者:Jeremy Zhou htt ...

  5. ei计算机投稿 知乎,知乎热议:科研有很水的idea应该发表出来吗?

    原标题:知乎热议:科研有很水的idea应该发表出来吗? 科研有很水的idea应该发表出来吗? - 来源:https://www.zhihu.com/question/372648294 小伙伴们,对于 ...

  6. P6056 [加油武汉]SIR 模型 看似高深实则很水的题

    题目Link:https://www.luogu.com.cn/problem/P6056 作为一道洛谷月赛的题, 太水了 你乍一看,还以为这道题很高级,又是β又是γ又是向上确取整,还有什么SIR模型 ...

  7. cocos2d 很水很水的看法

    这几天接了个扯淡的项目 cocos2d的 . 本来以为是Cpp的, 结果不是2dx ,而是OC的2d.看了几天的官方的dome ,大概知道是什么样子的.我就简单的纪录一下好了: cocos2d的整个框 ...

  8. 2753:走迷宫(dfs+初剪)//可以说是很水了。。。

    总时间限制:  1000ms 内存限制:  65536kB 描述 一个迷宫由R行C列格子组成,有的格子里有障碍物,不能走:有的格子是空地,可以走. 给定一个迷宫,求从左上角走到右下角最少需要走多少步( ...

  9. 别再问我为什么你敲的代码很水了!

    春节一过,迎来了"金三银四"的招聘旺季,各个大厂开始进入了大面积招兵买马的阶段,现在正是程序员进入大厂的最佳时期. 你是否有心仪的大厂想要跳槽呢?趁着这个黄金阶段把握机会,一举进入 ...

最新文章

  1. Request.ServerVariables参数集
  2. [铁道部信息化管理]号外
  3. SAE下修改models里面字段
  4. 深入Android 【一】 —— 序及开篇
  5. java客户端发送token_基于token的会话保持机制
  6. C#请求Post接口
  7. mysql工_mysql
  8. 为Openshift + MongoDb应用程序编写验收测试
  9. POJ 2287 - Tian Ji -- The Horse Racing(贪心)
  10. 11月16日云栖精选夜读:阿里云 oss JavaScript客户端签名文件上传 vue2.0
  11. No module named ‘yaml‘错误解决办法
  12. X86架构基本汇编指令详解
  13. java后台通过http请求下载文件
  14. 一英寸芯片大小_英寸,究竟是多大?
  15. 为什么苹果的官网看上去这么美
  16. The server encountered an internal error () that prevented it from fulfilling this requet异常解决
  17. 【R实验.7】回归分析
  18. 关于浏览器UA的一些介绍
  19. 框架学习:框架是什么以及框架怎么学
  20. 无法启动FiddlerScript 编辑器

热门文章

  1. PYTHON学习0022:函数基本介绍----2019-6-17
  2. 在电脑桌面怎样用命令开启远程桌面?
  3. 简单介绍tomcat中maxThreads,acceptCount,connectionTimeout
  4. 会员系统中需要验证用户的邮箱是否真实存在
  5. “Zhuang.Data”轻型数据库访问框架(二)框架的入口DbAccessor对象
  6. Java,开源,分享
  7. 基于DotNet构件技术的企业级敏捷软件开发平台 - AgileEAS.NET - 文章汇总及学习指南...
  8. postfix+postfixadmin+extmail邮件服务器架设过程
  9. C# Delegate(委托)与多线程
  10. 【正一专栏】为何我们要侥幸而又苟且地活着