Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #define NMAX 20
- #define LENMAX 30
- using namespace std;
- int n, used[NMAX];
- char s[NMAX][LENMAX], st[NMAX][LENMAX];
- void read() {
- cin >> n;
- cin.get();
- for (int i = 1; i <= n; i++)
- cin.getline(s[i], LENMAX);
- }
- void display() {
- for (int i = 1; i <= n; i++)
- cout << st[i] << ',';
- cout << endl;
- }
- void bktr(int k) {
- if (k == n + 1)
- display();
- else
- for (int i = 1; i <= n; i++)
- if (!used[i]) {
- strcpy(st[k], s[i]);
- used[i] = 1;
- bktr(k + 1);
- used[i] = 0;
- }
- }
- int main() {
- read();
- bktr(1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement