fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int x[100];
  4. int dem =0;
  5. int n;
  6. bool chuaxet[100];
  7. void Init(){
  8. cin >> n;
  9. for(int i = 1; i <= n; i++){
  10. chuaxet[i] = true;
  11. }
  12. }
  13. void Result(){
  14. for(int i = 1; i <= n;i++){
  15. cout << x[i] << " ";
  16. }
  17. }
  18. void Try(int i){
  19. for(int j = 1; j <= n; j++){
  20. if(chuaxet[j]){
  21. x[i] = j;
  22. chuaxet[j] = false;
  23. if(i == n)Result();
  24. else Try(i + 1);
  25. chuaxet[j] = true;
  26. }
  27. }
  28. }
  29. int main(){
  30. Init();
  31. Try(1);
  32. }
Success #stdin #stdout 0s 5276KB
stdin
Standard input is empty
stdout
Standard output is empty