擅长排列的小明

题目传送门:点击打开链接

//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 ;
}


posted @ 2015-10-06 11:07  Tovi  阅读(104)  评论(0编辑  收藏  举报