题目传送门:点击打开链接
//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',' '}; memset(b, 0, sizeof(b)); memset(c, 0, sizeof(c)); int n, m; cin >> n>> m; strcpy(b, a); b[m] = ' '; cout << b<< endl; while (next_permutation(a, a+n)) { strcpy(c, a); c[m] = ' '; if (strcmp(b, c)) { strcpy(b, c); b[m] = ' '; cout << b<< endl; } } } return 0 ; }