본문 바로가기

Competition/codeforces

Codeforces Round #527 (Div. 3) A. Uniform String

A. Uniform String

https://codeforces.com/problemset/problem/1092/A


같은 문자가 최대한 적게 나오게 해야한다.

n개를 출력하는데 n/k + n%k개가 minimum이다.

그래서 k주기로 쭉 출력한다.

만약 k가 4이고, n이 10이면 abcd abcd ab 이런식으로.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <bits/stdc++.h>
using namespace std;
 
int t, n, k;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(NULL); cout.tie(NULL);
    cin >> t;
    while (t--) {
        cin >> n >> k;
        for (int i = 0; i < n; i++) {
            cout << (char)('a' + i % k);
        }
        cout << '\n';
    }
    return 0;
}
cs