fork download
  1. /// no time to waste
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. int n;
  6. int a[11], used[11];
  7.  
  8. void dequy(int i) {
  9. if(i > n) {
  10. for(int j=1;j<=n;j++) cout << a[j] << ' ';
  11. cout << '\n';
  12. return;
  13. }
  14.  
  15. for(int j=1;j<=n;j++) {
  16. if(!used[j]) {
  17. used[j] = 1;
  18. a[i] = j;
  19. dequy(i + 1);
  20. used[j] = 0;
  21. }
  22. }
  23. return;
  24. }
  25.  
  26. int32_t main() {
  27. ios::sync_with_stdio(false);
  28. cin.tie(0), cout.tie(0);
  29. freopen("hoanvi.inp", "r", stdin);
  30. freopen("hoanvi.out", "w", stdout);
  31.  
  32. cin >> n;
  33. dequy(1);
  34. return 0;
  35. }
  36. /// code này chạy đúng (có thể), nhưng mà test cô chắc chắn được 1 điểm nhé=)). Vì test cô không
  37. /// cho in khoảng cách trên 1 dòng
Success #stdin #stdout 0.01s 5320KB
stdin
3
stdout
Standard output is empty