#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
int ncase, n, m, a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9}, buf[10];
cin >> ncase;
while (ncase--)
{
cin >> n >> m;
memcpy(buf, a, sizeof(int)*n);
//将数组a的前n个元素拷贝到buf的前n个元素中
for (int i=0; i<m; i++)
printf("%d", a[i]);
printf("\n");
while (next_permutation(a, a+n))//数组a前n个元素的下一个排列
{
if (memcmp(a, buf, sizeof(int)*m)!=0)
//比较数组a的前n个元素与buf的前m个元素是否相等
{
for (int i=0; i<m; i++)
printf("%d", a[i]);
printf("\n");
memcpy(buf, a, sizeof(int)*n);
}
}
}
return 0;
}
next_permutation,memcmp,memcpy
最新推荐文章于 2024-05-04 00:15:00 发布