-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy path1335B_ConstructtheString.cpp
More file actions
46 lines (37 loc) · 1.08 KB
/
1335B_ConstructtheString.cpp
File metadata and controls
46 lines (37 loc) · 1.08 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
~ Author : @tridib_2003
~ Title : 1335B. Construct the String
~ Link : https://codeforces.com/contest/1335/problem/B
*/
#include<bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int tc;
cin >> tc;
while (tc--) {
int n, a, b;
cin >> n >> a >> b;
string str;
int size = 0;
while (size < n) {
char ch = 'a';
for (int i = 1; i <= b; ++i) {
str.push_back(ch);
if (str.length() == n)
break;
++ch;
}
size += b;
}
cout << str << "\n";
}
return 0;
}
/* Algo -
1. 'b' distinct characters in a substring of length 'a', in a string of total length 'n'
2. form the string of length 'n' by repeating a set of exactly 'b' distinct characters
3. hence, any substring of length 'a' (>= b) is bound to have exactly 'b' distinct characters
4. Actually we dont need to take 'a' into consideration in our code !
*/