本文共 859 字,大约阅读时间需要 2 分钟。
#define _CRT_SECURE_NO_WARNINGS #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std;#define Size 27#define maxn 1<<30int mark[Size];int b[Size];char a[Size];set s;vector v;int len;void dfs(int pos){ if (pos > len){ vector ::iterator iter = v.begin(); for (; iter < v.end(); iter++) cout << *iter; cout << endl; return; } for (int i = 0; i < 26; i++){ if (b[i] && mark[i] == 0) { char c = i+ 'a'; v.push_back(c); mark[i] = 1; dfs(pos + 1); mark[i] = 0; v.pop_back(); } }}int main(){ cin >> a; len = strlen(a); for (int i = 0; i < len; i++) b[a[i] - 'a']++; dfs(1); system("pause"); return 0;}
转载于:https://www.cnblogs.com/MapReduce/p/8367402.html