Advertisement
STANAANDREY

permutari nume

Oct 19th, 2020 (edited)
1,839
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #define NMAX 20
  4. #define LENMAX 30
  5. using namespace std;
  6. int n, used[NMAX];
  7. char s[NMAX][LENMAX], st[NMAX][LENMAX];
  8.  
  9. void read() {
  10.     cin >> n;
  11.     cin.get();
  12.     for (int i = 1; i <= n; i++)
  13.         cin.getline(s[i], LENMAX);
  14. }
  15.  
  16. void display() {
  17.     for (int i = 1; i <= n; i++)
  18.         cout << st[i] << ',';
  19.     cout << endl;
  20. }
  21.  
  22. void bktr(int k) {
  23.     if (k == n + 1)
  24.         display();
  25.     else
  26.         for (int i = 1; i <= n; i++)
  27.             if (!used[i]) {
  28.                 strcpy(st[k], s[i]);
  29.                 used[i] = 1;
  30.                 bktr(k + 1);
  31.                 used[i] = 0;
  32.             }
  33. }
  34.  
  35. int main() {
  36.     read();
  37.     bktr(1);
  38.     return 0;
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement