您的位置:首页 > 其它

擅长排列的小明

2015-10-06 11:07 260 查看
题目传送门:点击打开链接

//stl里面的next_permutation函数的运用
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
#include <algorithm>
using namespace std;

char b[10], c[10];

int main() {
int t;
cin >> t;
while (t --) {
char a[10] = {'1','2','3','4','5','6','7','8','9','\n'};
memset(b, 0, sizeof(b));
memset(c, 0, sizeof(c));
int n, m;
cin >> n>> m;
strcpy(b, a);
b[m] = '\0';
cout << b<< endl;
while (next_permutation(a, a+n)) {
strcpy(c, a);
c[m] = '\0';
if (strcmp(b, c)) {
strcpy(b, c);
b[m] = '\0';
cout << b<< endl;
}
}
}

return 0 ;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: