-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreverse.cpp
More file actions
52 lines (45 loc) · 948 Bytes
/
reverse.cpp
File metadata and controls
52 lines (45 loc) · 948 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <bits/stdc++.h>
using namespace std;
#define MAX 2*100000
int a[MAX];
int b[MAX];
int main()
{
long long int n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
int left, right;
if (n == 2) {
cout << a[1] << " " << a[0];
return 0;
}
int flag = n % 2;
if (flag == 0) {
right = n / 2;
left = right-1;
} else {
right = (n+1) / 2;
left = n / 2;
}
for (int i = 0; i < n; i++) {
if (flag == 0) {
if (i % 2 == 0)
b[right++] = a[i];
else
b[left--] = a[i];
} else {
if (i % 2 == 0)
b[left--] = a[i];
else
b[right++] = a[i];
if (i == n-1)
b[0] = a[i];
}
}
for (int i = 0; i < n; i++) {
cout << b[i];
if (i < n-1)
cout << " ";
}
}