UVA - 10098 - Generating Fast (枚举排列)





思路:生成全排列,用next_permutation。注意生成之前先对那个字符数组排序。


AC代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

char str[20];

int main() {
	int n;
	cin >> n;
	while(n--) {
		scanf("%s", str);
		int len = strlen(str);
		sort(str, str + len);
		do
		{
			printf("%s\n", str);
		}while(next_permutation(str, str + len));
		printf("\n");
	}
	return 0;
} 












posted @ 2016-02-22 17:10  zfyouxi  阅读(166)  评论(0编辑  收藏  举报