Advertisement
pasholnahuy

Строки из k символов длины n

Jun 12th, 2023
819
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. void print_string(string &cur_string, int bits_count, const int k, vector<char> &alf) {
  7.     if (bits_count == 0) {
  8.         cout << cur_string << '\n';
  9.         return;
  10.     }
  11.     for (int i = k - 1; i >= 0; --i) {
  12.         cur_string.push_back(alf[i]);
  13.         print_string(cur_string, bits_count - 1, k, alf);
  14.         cur_string.pop_back();
  15.     }
  16.  
  17. }
  18.  
  19. int main() {
  20.     int n, k;
  21.     cin >> n >> k;
  22.     vector<char> alf = {};
  23.     for (char i = char('a'); i <= char('z'); ++i){
  24.         alf.push_back(i);
  25.     }
  26.     string s;
  27.     print_string(s, n, k, alf);
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement