Full array in STL (2)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.