B. Construct the String (字符串+思维)

B. Construct the String
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given three positive integers nn, aa and bb. You have to construct a string ss of length nn consisting of lowercase Latin letters such that each substring of length aa has exactly bb distinct letters. It is guaranteed that the answer exists.

You have to answer tt independent test cases.

Recall that the substring s[lr]s[l…r] is the string sl,sl+1,,srsl,sl+1,…,sr and its length is rl+1r−l+1. In this problem you are only interested in substrings of length aa.

Input

The first line of the input contains one integer tt (1t20001≤t≤2000) — the number of test cases. Then tt test cases follow.

The only line of a test case contains three space-separated integers nn, aa and bb (1an2000,1bmin(26,a)1≤a≤n≤2000,1≤b≤min(26,a)), where nn is the length of the required string, aa is the length of a substring and bb is the required number of distinct letters in each substring of length aa.

It is guaranteed that the sum of nn over all test cases does not exceed 20002000 (n2000∑n≤2000).

Output

For each test case, print the answer — such a string ss of length nn consisting of lowercase Latin letters that each substring of length aa has exactly bb distinct letters. If there are multiple valid answers, print any of them. It is guaranteed that the answer exists.

Example
input
Copy
4
7 5 3
6 1 1
6 6 1
5 2 2
output
Copy
tleelte
qwerty
vvvvvv
abcde
Note

In the first test case of the example, consider all the substrings of length 55:

  • "tleel": it contains 33 distinct (unique) letters,
  • "leelt": it contains 33 distinct (unique) letters,
  • "eelte": it contains 33 distinct (unique) letters.
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 using namespace std;
 5 #define scanf scanf_s
 6 
 7 int T;
 8 int n, a, b;
 9 int main() {
10     scanf("%d", &T);
11     while (T--) {
12         scanf("%d%d%d", &n, &a, &b);
13         char s[10001];
14         for (int i = 0; i < n; i++) {
15             s[i] = 'a' + i % b;
16         }
17         s[n] = '';
18         printf("%s
", s);
19     }
20 
21     return 0;
22 }
原文地址:https://www.cnblogs.com/sineagle/p/14476697.html