B. Construct the String (字符串+思维)
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[l…r]s[l…r] is the string sl,sl+1,…,srsl,sl+1,…,sr and its length is r−l+1r−l+1. In this problem you are only interested in substrings of length aa.
The first line of the input contains one integer tt (1≤t≤20001≤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 (1≤a≤n≤2000,1≤b≤min(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 (∑n≤2000∑n≤2000).
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.
4 7 5 3 6 1 1 6 6 1 5 2 2
tleelte qwerty vvvvvv abcde
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] = '\0'; 18 printf("%s\n", s); 19 } 20 21 return 0; 22 }