字符串的全排列,递归交换
#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <bitset>
#include <list>
#include <map>
#include <set>
#include <iterator>
#include <algorithm>
#include <functional>
#include <utility>
#include <sstream>
#include <climits>
#include <cassert>
#define BUG puts("here!!!");
using namespace std;
const int N = 1005;
void swap(char &a, char &b) {
char temp = a;
a = b;
b = temp;
}
void f(char *str, char *begin) {
if(*begin == '\0') {
cout << str << endl;
return;
}
for(char *p = begin; *p != '\0'; p++) {
swap(*p, *begin);
f(str, begin+1);
swap(*p, *begin);
}
}
int main() {
char s[10] = "abcde";
f(s, s);
return 0;
}