Advertisement
shek_shek

Генерация перестановок

Sep 13th, 2014
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stack>
  3. #include<math.h>
  4. #include<time.h>
  5. #include<iostream>
  6. #include<algorithm>
  7. #include<string>
  8. #include<set>
  9. #include<iomanip>
  10. #include<vector>
  11. #include<map>
  12. #include<cassert>
  13. #include<queue>
  14. #include <tuple>
  15.  
  16.  
  17. using namespace std;
  18.  
  19. typedef long long li;
  20. typedef long double ld;
  21.  
  22. #define forn(i, n) for (int i = 0; i < int(n); ++i)
  23. #define pb push_back
  24. #define mp make_pair
  25. #define shek_shek _DEBUG
  26. #define mt make_tuple
  27. #define aaaa(n) get<(n)>(aaaa)
  28. #define all(v) v.begin(),v.end()
  29. #define EPS  1e-9
  30. #define PI 3.1415926535897932384626433832795
  31.  
  32.  
  33. typedef long long li;
  34. typedef long double ld;
  35. typedef pair <int, int> pt;
  36.  
  37. #define ALPH "123456789"
  38. #define DEPTH (9)
  39.  
  40. char s[DEPTH];
  41.  
  42. bool used[DEPTH];
  43.  
  44. void rec (int x) {
  45.     if (x == DEPTH) {
  46.         printf("%s\n", s);
  47.         return;
  48.     }
  49.     for (int i = 0; i < DEPTH; i++) {
  50.         if (!used[i]) {
  51.             used[i] = true;
  52.             s[x] = ALPH[i];
  53.             rec(x + 1);
  54.             used[i] = false;
  55.         }
  56.     }
  57. }
  58.  
  59.  
  60.  
  61. int main () {
  62. #ifdef shek_shek
  63.     freopen("input.txt", "r", stdin);
  64.     freopen("output.txt", "w", stdout);
  65. #endif
  66.     rec(0);
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement