zoukankan      html  css  js  c++  java
  • CodeForces

    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 ll to rr as s[lr]s[l…r] .

    Your task is to construct such string ss of minimum possible length that there are exactly kk positions ii such that s[ii+n1]=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 tt .

    It is guaranteed that the answer is always unique.

    Input

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

    The second line of the input contains the string tt consisting of exactly nn lowercase Latin letters.

    Output

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

    It is guaranteed that the answer is always unique.

    Examples

    Input
    3 4
    aba
    Output
    ababababa
    Input
    3 2
    cat
    Output
    catcat
    #include <cstdio>
    #include <iostream>
    #include <cmath>
    #include <string>
    #include <cstring>
    #include <algorithm>
    #include <queue>
    using namespace std;
    int main()
    {
        int n, k, miao;
        string s, t;
        while(~scanf("%d%d", &n, &k) && (n+k))
        {
            cin >> s;
            miao = 0;
            for(int i = 1; i<n; i++)
            {
                t = s.substr(i);
                if(s.find(t) == 0)
                {
                    miao = i;
                    break;
                }
            }
            if(miao)
            {
                string root = s.substr(0, miao);
                for(int i = 0; i<k; i++)
                {
                    cout << root;
                }
                cout << t << '
    ';
            }
            else
            {
                for(int i = 0; i<k; i++)
                {
                    cout << s;
                }
            }
        }
        return 0;
    }
  • 相关阅读:
    SEM关键词的三种分类方式
    分分钟解决 MySQL 查询速度慢与性能差
    为什么notify(), wait()等函数定义在Object中,而不是Thread中
    wait(), notify(), notifyAll()等方法介绍
    Java中的Volatile和synchronized的区别
    史上最简单的 SpringCloud 教程
    如何用git将项目代码上传到github
    常见排序
    【CodeForces】9B-Running Student
    【CodeForces】9A-Die Roll
  • 原文地址:https://www.cnblogs.com/RootVount/p/10467406.html
Copyright © 2011-2022 走看看