Skip to content

Instantly share code, notes, and snippets.

@gavincyi
Created December 9, 2016 07:12
Show Gist options
  • Select an option

  • Save gavincyi/400577176e69af5e20c122eb308f55d2 to your computer and use it in GitHub Desktop.

Select an option

Save gavincyi/400577176e69af5e20c122eb308f55d2 to your computer and use it in GitHub Desktop.
// you can use includes, for example:
#include <algorithm>
#include <string>
#include <iostream>
using namespace std;
#define vii vector<pair<int, int>>
#define pii pair<int, int>
#define g0( a ) get<0>( a )
#define g1( a ) get<1>( a )
void Permutate(string& s, int index) {
if (index == s.size() - 1) {
cout << s << endl;
} else {
for (int i = index; i < s.size(); i++) {
swap(s[index], s[i]);
Permutate(s, index + 1);
swap(s[i], s[index]);
}
}
}
int main() {
auto s = string{"abcd"};
Permutate(0);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment