La verdad es que e ciado en un código spaghetti horrible pero se suponía que este programa era fácil, verán lo que necesito es que se generen las permutaciones de un numero y que después de cada permutación las cuente es decir
Numero Permutaciones
123 0
132 1
213 1
231 2
321 2
Para esto he encontrado un codigo aqui mismo, que genera las permutaciones y luego pasa por un ordenamiento que solo cuenta las permutaciones. El problema es que las permutaciones las cuenta mal, alguien podría ayudarme porfavor!
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> v_int;
int N = 3; // n first natural numbers
for (int i = 1; i<=N; i++)
v_int.push_back(i);
/* Use a do/while loop instead of the normal while loop becuase
the first entry will be skipped if you call next_permutation
first */
int cnt = 0;
do {
// There should be n! (4*3*2*1) entries.
cout << ++cnt << ": ";
// Print out the vector.
for(unsigned int x = 0; x < v_int.size(); x++)
cout << v_int[x];
//Conteo de permutaciones
int pasadas;
int i;
int almacena;
int b;
int num;
int x;
b=0;
for (pasadas = 1; pasadas < 3 ; pasadas++ ) {
for (x=0; x < 2; x++) {
if (v_int [x] > v_int[x+1]) {
b=b+1;
}
}
}
printf( "\nNumero de Permutaciones\n");
printf("%4d", b);
printf("\n");
cout << endl;
} while(next_permutation(v_int.begin(), v_int.end()));
system("pause");
return 0;
}




