Advertisement
StabCrab

Четвертый номер

Mar 15th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <cmath>
  4. using namespace std;
  5. string sum(string a, int SS)
  6. {
  7.     std::reverse(a.begin(), a.end());
  8.     int n = 0;
  9.     a[n] += 1;
  10.     while (a[n] == 97 + SS)
  11.     {
  12.         a[n] = 'a';
  13.         a[n+1] += 1;
  14.         n++;
  15.     }
  16.     std::reverse(a.begin(), a.end());
  17.     return a;
  18. }
  19. int main() {
  20.     int length, SS;
  21.     cin >> length;
  22.     cin >> SS;
  23.     string a;
  24.     for (int i = 0; i < length; i++)
  25.         a += 'a';
  26.     for (int i = 0; i < pow(SS, length); i++)
  27.     {
  28.         cout << a << endl;
  29.         a = sum(a, SS);
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement