首页 > 学院 > 开发设计 > 正文

openJudge 全排列算法

2019-11-06 07:48:51
字体:
来源:转载
供稿:网友
#include <iostream>#include <cstdio>#include <iostream>#include <algorithm>#include <cstring>using namespace std;const int M = 8;char str[M];char permutation[M];bool used[M] = { 0 };int L = 0;void Permutation(int n){	if (n == L)	{		permutation[L] = 0;		cout << permutation << endl;		return;	}	for (int i = 0; i < L; ++i)	{		if (!used[i])		{			used[i] = true;			permutation[n] = str[i];			Permutation(n + 1);			used[i] = false;		}	}}int main(){	cin >> str;	L = strlen(str);	sort(str, str + L);	Permutation(0);	return 0;}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表