[TOJ 2621] (next_permutation of STL ),
Description
Any input of n non-repeated integer sequences is in full order.
Input
There are multiple groups of test data. The first line is an integer t (0 <t <20), representing the number of test groups. Each group of test data has two rows. The first row is the number of integers n (0 <n <6), and the second row is n non-repeated integers.
Output
The output sequence is arranged in ascending order. A blank line is output after each test data.
Sample Input
1
3
1 3 5
Sample output
1 3 5
1 5 3
3 1 5
3 5 1
5 1 3
5 3 1
# Include <iostream> # include <algorithm> using namespace std; int cmp (int a, int B) {return a <B;} int main () {int a [100], t, n, I; cin> t; while (t --) {cin> n; for (I = 0; I <n; I ++) scanf ("% d", & a [I]); sort (a, a + n, cmp ); // you must first sort the array elements from small to large for (I = 0; I <n; I ++) // first (completely small to large) sorting output {if (I! = N-1) printf ("% d", a [I]); else printf ("% d \ n", a [I]);} while (next_permutation (, a + n) // each time it is rearranged until it is arranged completely from large to small {for (I = 0; I <n; I ++) {if (I! = N-1) printf ("% d", a [I]); else printf ("% d \ n", a [I]);} cout <endl ;}}