#include <iostream>
#include <vector>
using namespace std;
typedef vector<string> VS;
void back(VS ¶ules, VS &sol, int n, int i) {
if(i == n) {
cout << "{" << sol[0];
for(int j = 1; j < n; j++) {
cout << "," << sol[i];
}
cout << "}" << endl;
}
else {
for(int j = 0; j < n; j++) {
sol[i] = paraules[j];
back(paraules, sol, n, i+1);
}
}
}
int main() {
int n;
cin >> n;
VS sol(n);
VS paraules(n);
for(int i = 0; i < n; i++) {
cin >> paraules[i];
}
cout << "This won t print";
back(paraules, sol, n, 0);
}
Pasted the whole code now. A backtracking that takes n
words, and just prints all the permutations of the words.
I initially thought it was a problem with the reading since the this wont print
wasn't printing. After some testing, I've discovered that commenting the function call on the last line makes the error disappear, and the code doesn't crash anymore.
So it's maybe the function? This still doesn't explain why it's not printing, since the call happens after the cout
.
As an example input might be:
2 hi bye