#include <iostream> #include <vector> #include <algorithm> #include <iterator> int pow2(int x) { return 1 << x; } int main() { size_t n, t; std::cin >> n >> t; std::vector<int> as(pow2(n)); std::copy_n(std::istream_iterator<int>(std::cin), pow2(n), as.begin()); if (t % 2 == 0) std::copy_n(as.begin(), pow2(n), std::ostream_iterator<int>(std::cout, " ")); else std::copy_n(as.rbegin(), pow2(n), std::ostream_iterator<int>(std::cout, " ")); std::cout << std::endl; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #include <iostream> #include <vector> #include <algorithm> #include <iterator> int pow2(int x) { return 1 << x; } int main() { size_t n, t; std::cin >> n >> t; std::vector<int> as(pow2(n)); std::copy_n(std::istream_iterator<int>(std::cin), pow2(n), as.begin()); if (t % 2 == 0) std::copy_n(as.begin(), pow2(n), std::ostream_iterator<int>(std::cout, " ")); else std::copy_n(as.rbegin(), pow2(n), std::ostream_iterator<int>(std::cout, " ")); std::cout << std::endl; } |