STANAANDREY

alternator letters

Oct 26th, 2020
791
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. ///****************
  4. string create() {
  5.     string alfa = "";
  6.     for (char c = 'a'; c <= 'z'; c++)
  7.         alfa += c;
  8.     return alfa;
  9. }
  10. const string alfa = create();
  11. int n, k;
  12. string st;
  13.  
  14. void bktr(int top) {
  15.     if (n == top) {
  16.         puts(st.c_str());
  17.         return;
  18.     }
  19.     for (int i = 0; i < k; i++) {
  20.         st[top] = alfa[i];
  21.         bktr(top + 1);
  22.     }
  23. }
  24.  
  25. int main() {
  26.     cin >> n >> k;
  27.     assert(k >= 1 && k <= alfa.size());
  28.     st.resize(n + 3);
  29.     bktr(0);
  30.     return 0;
  31. }
  32.  
RAW Paste Data