codeforces/#506 div3

A. Many Equal Substrings

공부정리 2018. 8. 29. 15:10

s문자열을 이용해서 s문자열이 k번 나타나도록 출력하는 문제.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <algorithm>
using namespace std;
 
char s[52];
 
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int n, k;
    cin >> n >> k;
    cin >> s;
    int po = 0;
    int j = 1;
    for (; j < n; ++j) {
        int i = 0;
        for (; i < n; ++i) 
            if (j + i >= n || s[i] != s[j + i]) break;
        if (j + i == n) break;
    }
    for (int i = 0; i < k - 1++i) 
        for (int l = 0; l < j; ++l) 
            cout << s[l];
    cout << s;
    return 0;
}
cs