Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. bool NextSet(int *a, int n, int m)
  4. {
  5.   int j = m - 1;
  6.   while (>= 0 && a[j] == n) j--;
  7.   if (< 0) return false;
  8.   if (a[j] >= n)
  9.     j--;
  10.   a[j]++;
  11.   if (== m - 1) return true;
  12.   for (int k = j + 1; k < m; k++)
  13.     a[k] = 1;
  14.   return true;
  15. }
  16. void Print(int *a, int n) 
  17. {
  18.   static int num = 1;
  19.   cout.width(3);
  20.   cout << num++ << ":  ";
  21.   for (int i = 0; i < n; i++)
  22.     cout << a[i] << " ";
  23.   cout << endl;
  24. }
  25. int main() 
  26. {
  27.   int n, m, *a;
  28.   cout << "N = ";
  29.   cin >> n;
  30.   cout << "M = ";
  31.   cin >> m;
  32.   int h = n > m ? n : m; // размер массива а выбирается как max(n,m)
  33.   a = new int[h];
  34.   for (int i = 0; i < h; i++)
  35.     a[i] = 1;
  36.   Print(a, m);
  37.   while (NextSet(a, n, m))
  38.     Print(a, m);
  39.   cin.get(); cin.get();
  40.   return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement