Skip to content

Commit 938fc22

Browse files
committed
Create 1638A-Reverse.cpp
1 parent 463893d commit 938fc22

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

1638A-Reverse.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <cstdio>
2+
#include <vector>
3+
4+
int main(){
5+
6+
long t; scanf("%ld", &t);
7+
while(t--){
8+
long n; scanf("%ld", &n);
9+
std::vector<long> a(n + 1); long start(-1), stop(-1);
10+
for(long p = 1; p <= n; p++){
11+
scanf("%ld", &a[p]);
12+
if(start < 0 && p != a[p]){start = p;}
13+
else if(a[p] == start){stop = p;}
14+
}
15+
16+
for(long p = 0; start > 0 && 2 * p <= stop - start; p++){
17+
long tmp = a[start + p];
18+
a[start + p] = a[stop - p];
19+
a[stop - p] = tmp;
20+
}
21+
22+
for(long p = 1; p <= n; p++){printf("%ld ", a[p]);}
23+
puts("");
24+
}
25+
26+
}

0 commit comments

Comments
 (0)