#include <iostream> #include <cstdlib> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, t, size; int *a; cin >> n >> t; size = (1 << n); t &= 1; a = new int[size]; for (int i = 0; i < size; ++i) cin >> a[i]; if (t == 0) { for (int i = 0; i < size-1; ++i) cout << a[i] << " "; cout << a[size-1] << endl; } else { for (int i = size-1; i > 0; --i) cout << a[i] << " "; cout << a[0] << endl; } delete[] a; return 0; }
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 | #include <iostream> #include <cstdlib> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, t, size; int *a; cin >> n >> t; size = (1 << n); t &= 1; a = new int[size]; for (int i = 0; i < size; ++i) cin >> a[i]; if (t == 0) { for (int i = 0; i < size-1; ++i) cout << a[i] << " "; cout << a[size-1] << endl; } else { for (int i = size-1; i > 0; --i) cout << a[i] << " "; cout << a[0] << endl; } delete[] a; return 0; } |