Nyoj-366-D small L (for full Arrangement), nyoj-366-d for full Arrangement

Source: Internet
Author: User

Nyoj-366-D small L (for full Arrangement), nyoj-366-d for full Arrangement
D small L time limit: 4000 MS | memory limit: 65535 KB difficulty: 2

Description
One day, TC went to the ACM's Xiao L to play with the Three Kingdoms, but this would be a little busy. I don't want to play with Kuang, but I'm afraid of being angry, at this time, Xiao L gave me a question to solve (Xiao L is very D), there is a number of n (0 <n <10), write a full arrangement of 1 to n, at this moment, I am a little confused. Can you help me solve the problem intelligently?
Input
Enter N (0 <N <10) in the first row, indicating that N groups of test data exist. The next N rows Input Multiple groups of input data, each group of input data is an integer x (0 <x <10)
Output
Output all combinations in a specific order.
Specific order: Values in each combination are arranged in ascending order, and the combinations are arranged in lexicographically.
Sample Input
223
Sample output
1221123132213231312321
Source
Original
Uploaded
Kapop
1/* 2 * http://acm.nyist.edu.cn/JudgeOnline/problem.php? Pid = 366 3 * by jtahstu on 4 * knowledge point: sort the generator in the lexicographically next order next_permutation () 5 * sort by prev_permutation () in the lexicographically previous order () 6 */7 8 # include <iostream> 9 # include <algorithm> 10 # include <string> 11 using namespace std; 12 13 int main () {14 int n; 15 cin> n; 16 while (n --) 17 {18 int m; 19 string s; 20 cin> m; 21 for (int I = 1; I <= m; I ++) 22 s + = I + '0'; 23 cout <s <endl; 24 while (next_permutation (s. begin (), s. end () 25 cout <s <endl; 26} 27 return 0; 28}
 3 #include<iostream> 4 #include<algorithm> 5 using namespace std; 6 int a[]={1,2,3,4,5,6,7,8,9}; 7 int main() 8 { 9     int n,r;10     cin>>r;11     while(r--)12     {13      cin>>n;14      do15      {16      for(int i=0;i<n;i++)17          cout<<a[i];18      cout<<endl;19      }while(next_permutation(a,a+n));20     }21  return 0;22 }        

 

 

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.