fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <iterator>
  4. #include <utility>
  5. #include <vector>
  6.  
  7. using namespace std;
  8.  
  9. struct ComparePair
  10. {
  11. bool operator()(const pair<int, int> &lhs, const pair<int, int> &rhs)
  12. {
  13. return lhs.first < rhs.first;
  14. }
  15. }comparePair;
  16.  
  17. int main(int argc, char *argv[])
  18. {
  19. ////////////////////////////
  20. // Custom
  21. vector<pair<int, int> > v;
  22.  
  23. v.push_back(pair<int, int>(1, 3000));
  24. v.push_back(pair<int, int>(3, 5000));
  25. v.push_back(pair<int, int>(2, 9000));
  26.  
  27. sort(v.begin(), v.end(), comparePair);
  28.  
  29. do
  30. {
  31. for(const auto &i : v)
  32. {
  33. cout << i.first << ' ' << i.second << ' ';
  34. }
  35. putchar('\n');
  36. }
  37. while(next_permutation(v.begin(), v.end(), comparePair));
  38.  
  39. ////////////////////////////
  40. // Default
  41. int arr[] = {1, 2, 3};
  42. do
  43. {
  44. // Do something
  45. for(const int i : arr)
  46. printf("%d ", i);
  47. putchar('\n');
  48. }
  49. while(next_permutation(arr, arr+3));
  50.  
  51. return 0;
  52. }
Success #stdin #stdout 0s 4160KB
stdin
Standard input is empty
stdout
1 3000 2 9000 3 5000 
1 3000 3 5000 2 9000 
2 9000 1 3000 3 5000 
2 9000 3 5000 1 3000 
3 5000 1 3000 2 9000 
3 5000 2 9000 1 3000 
1 2 3 
1 3 2 
2 1 3 
2 3 1 
3 1 2 
3 2 1