Write a program that, given n different words s_1, \dots, s_n, prints all the permutations that can be made up with the words.

Input: Input consists of a number n > 0, followed by s_1,\dots, s_n.

Output: Print all the permutations that can be made up with s_1, \dots, s_n.

You can print the solutions to this exercise in any order.

Use the template for backtracking.

A way to do this exercise could be to have a vector<string> words to store all the words and a vector<int> sol to store indices of the words in the solution.

// Permutations of words
#include<iostream>
#include<vector>
#include<string>

using namespace std;

void write (const vector<int> & v, const vector<string>& words){
    cout << '(' << words[v[0]];
    for (size_t i = 1; i < v.size(); ++i)
        cout << ',' << words[v[i]];
    cout << ')' << endl;
}

void perm(vector<int>& sol, int k, vector<bool> used, const vector<string>& words){
 //put code here
}

int main(){
    int n;
    cin >> n;
    vector<string> words(n,"");
    for (int i = 0;  i < n; ++i)
        cin >> words[i];
    vector<int> sol(n,0);
    vector<bool> used(n, false);
    perm(sol, 0, used, words);
}
// Permutations of words
#include<iostream>
#include<vector>
#include<string>

using namespace std;

void write (const vector<int> & v, const vector<string>& words){
    cout << '(' << words[v[0]];
    for (size_t i = 1; i < v.size(); ++i)
        cout << ',' << words[v[i]];
    cout << ')' << endl;
}

void perm(vector<int>& sol, int k, vector<bool> used, const vector<string>& words){
    int n = sol.size();
    if (k == n) write(sol, words);
    else{
        for (int i = 0; i < n; ++i){
            if (not used[i]){
                sol[k] = i;
                used[i] = true;
                perm(sol, k+1, used, words);
                used[i] = false;
            }
        }
    }
}

int main(){
    int n;
    cin >> n;
    vector<string> words(n,"");
    for (int i = 0;  i < n; ++i)
        cin >> words[i];
    vector<int> sol(n,0);
    vector<bool> used(n, false);
    perm(sol, 0, used, words);
}