LightOj-1023-Discovering Permutations

来源:互联网 发布:西安新城网络花店 编辑:程序博客网 时间:2024/06/06 01:49

题目传送门


题意:输出A-Z里面前N个字母的全排列的前K个。

思路:使用next_permutation()函数。

#include <bits/stdc++.h>using namespace std;int main(void){    int T,cas=1;    scanf("%d", &T);    while (T--)    {        int n, k;        scanf("%d %d", &n, &k);        char ch[30];        for (int i = 0; i < n; i++)            ch[i] = 'A'+i;        printf("Case %d:\n",cas++);        do        {            if (!k)                break;            k--;            for (int i = 0; i < n; i++)                printf("%c", ch[i]);            printf("\n");        }while (next_permutation(ch, ch+n));    }    return 0;}
原创粉丝点击