终于知道为什么总是不过测试点2了!!
A. Special Permutation
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
You are given one integer nn (n>1n>1).
Recall that a permutation of length nn is an array consisting of nn distinct integers from 11 to nn in arbitrary order. For example, [2,3,1,5,4][2,3,1,5,4] is a permutation of length 55, but [1,2,2][1,2,2] is not a permutation (22 appears twice in the array) and [1,3,4][1,3,4] is also not a permutation (n=3n=3 but there is 44 in the array).
Your task is to find a permutation pp of length nn that there is no index ii (1≤i≤n1≤i≤n) such that pi=ipi=i (so, for all ii from 11 to nn the condition pi≠ipi≠i should be satisfied).
You have to answer tt independent test cases.
If there are several answers, you can print any. It can be proven that the answer exists for each n>1n>1.
Input
The first line of the input contains one integer tt (1≤t≤1001≤t≤100) — the number of test cases. Then tt test cases follow.
The only line of the test case contains one integer nn (2≤n≤1002≤n≤100) — the length of the permutation you have to find.
Output
For each test case, print nn distinct integers p1,p2,…,pnp1,p2,…,pn — a permutation that there is no index ii (1≤i≤n1≤i≤n) such that pi=ipi=i (so, for all ii from 11 to nn the condition pi≠ipi≠i should be satisfied).
If there are several answers, you can print any. It can be proven that the answer exists for each n>1n>1.
Example
input
Copy
2 2 5
output
Copy
2 1 2 1 5 3 4
#include<iostream>
using namespace std;
int main(void)
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
if(n%2==0)
{
for(int i=n; i>0;i--)
cout<<i<<" ";
}
else
{
for(int i =n-1;i>1;i--)
{
cout<<i<<" ";
}
cout<<n<<" ";
if(n!=1){
cout<<1<<" ";
}
}
}
return 0;
}