UVaOJ 10098 - Generating Fast

来源:互联网 发布:淘宝上如何卖游戏币 编辑:程序博客网 时间:2024/05/09 18:20


——by A Code Rabbit


Description

输入一个序列,要求输出这个序列所属的所有全排列。


Types

Brute Force :: Elementary Skills


Analysis

用 perv_permutation( )把序列变成所有全排列最小的那个,然后再用next_permutation( )边变大边输出。

要注意两个函数会发生“回绕”。


Solution

// UVaOJ 10098// Generating Fast// by A Code Rabbit#include <algorithm>#include <cstdio>#include <cstring>using namespace std;const int LIMITS = 12;int n;char str[LIMITS];int main() {    scanf("%d", &n);    getchar();    while (n--) {        gets(str);        int len = strlen(str);        while (prev_permutation(str, str + len)) {        }        next_permutation(str, str + len);        do {            puts(str);        } while (next_permutation(str, str + len));        printf("\n");    }    return 0;}









下载PDF

参考资料:无


原创粉丝点击