[TOJ 2621] (next_permutation of STL ),

Source: Internet
Author: User

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

 

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.