Topic H: Good at arranging Xiao Ming time limit: Sec Memory limit: MB
submitted: 17 Resolution:
Submitted State Forum Title Description
Xiaoming is very clever, and he is very good at arranging calculations. For example, give Xiaoming a number 5, he can immediately give 1-5 by the dictionary order of the full array, if you want to embarrass him, in the 5 numbers to choose a few numbers to keep him in the whole line, then you are wrong, he is also very good. Now you need to write a program to verify that Bob is good at arranging.
Input
the first line of input integer N (1<n<10) represents how many sets of test data
Each group of test data first row two integers n m (1<n<9,0<m<=n)
Output
Select M characters in 1-n to be fully arranged, all output by dictionary order, one row for each arrangement, and no demarcation between each set of data. As examples
Sample input3 offSample output123121314212324313234414243123132213231312321TipsSTL (The data is a bit large, do not care about the time limit) on the processing of characters.
#include <iostream>
#include <algorithm>
#include <string>
using
namespace
std;
int
main()
{
int
i,j,k,T;
cin>>T;
while
(T--)
{
int
x,y;
string s1,s2;
cin>>x>>y;
for
(i=1; i<=x; i++)
{
s1+=
‘0‘
+i;//将字符的每一位赋初值
}
s2=s1.substr(0,y);//截取字符s1,从0to the position of Y and copy to S2;
cout<<s2<<endl;
next_permutation(s1.begin(),s1.end());//对s1进行全排列,从开头到接尾。s1.begin()开始s1.end()结尾。
do
{
if
(s2!=s1.substr(0,y))//判断是否截取和排列后的前y是否一样。
{
s2=s1.substr(0,y);
cout<<s2<<endl;
}
}
while
(next_permutation(s1.begin(),s1.end()));//对s1进行全排列,从开头到接尾。s1.begin()开始s1.end()结尾。
}
return
0;
}
Full array in STL (2)