#include <stdio.h>
#include <istream>
#include <iostream>
int computePower(int a, int n)
{
int result = 1;
for(int i = 0; i < n; i++)
{
result *= a;
}
return result;
}
class Input {
private:
int n;
int t;
int numOfCards;
short* cards;
public:
Input(int n, int t)
{
this->n = n;
this->t = t;
numOfCards = computePower(2, n);
cards = new short[numOfCards];
}
virtual ~Input()
{
delete[] cards;
}
int getN()
{
return n;
}
int getT()
{
return t;
}
short getCard(int i)
{
return this->cards[i];
}
void setCard(int i, short val)
{
this->cards[i] = val;
}
int getNumOfCards()
{
return numOfCards;
}
};
void sampleInputUsage()
{
Input* i = new Input(2, 1);
i->getN();
i->getT();
i->getCard(0);
delete i;
}
Input* parseInput(std::istream &is)
{
int n = 0;
int t = 0;
is >> n;
is >> t;
Input* result = new Input(n, t);
for(int i = 0; i < result->getNumOfCards(); i++)
{
int val = 0;
is >> val;
result->setCard(i, val);
}
return result;
}
void printInputReversed(Input* input, std::ostream &os)
{
for(int i = input->getNumOfCards()-1; i >= 0; i--)
{
os << input->getCard(i);
if(i > 0)
{
os << " ";
}
}
}
void printInput(Input* input, std::ostream &os)
{
for(int i = 0; i < input->getNumOfCards(); i++)
{
os << input->getCard(i);
if(i < input->getNumOfCards()-1)
{
os << " ";
}
}
}
int main(int argc, char* argv[])
{
Input* input = parseInput(std::cin);
if(input->getT() & 0x01)
{
printInputReversed(input, std::cout);
}
else
{
printInput(input, std::cout);
}
std::cout << std::endl;
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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | #include <stdio.h> #include <istream> #include <iostream> int computePower(int a, int n) { int result = 1; for(int i = 0; i < n; i++) { result *= a; } return result; } class Input { private: int n; int t; int numOfCards; short* cards; public: Input(int n, int t) { this->n = n; this->t = t; numOfCards = computePower(2, n); cards = new short[numOfCards]; } virtual ~Input() { delete[] cards; } int getN() { return n; } int getT() { return t; } short getCard(int i) { return this->cards[i]; } void setCard(int i, short val) { this->cards[i] = val; } int getNumOfCards() { return numOfCards; } }; void sampleInputUsage() { Input* i = new Input(2, 1); i->getN(); i->getT(); i->getCard(0); delete i; } Input* parseInput(std::istream &is) { int n = 0; int t = 0; is >> n; is >> t; Input* result = new Input(n, t); for(int i = 0; i < result->getNumOfCards(); i++) { int val = 0; is >> val; result->setCard(i, val); } return result; } void printInputReversed(Input* input, std::ostream &os) { for(int i = input->getNumOfCards()-1; i >= 0; i--) { os << input->getCard(i); if(i > 0) { os << " "; } } } void printInput(Input* input, std::ostream &os) { for(int i = 0; i < input->getNumOfCards(); i++) { os << input->getCard(i); if(i < input->getNumOfCards()-1) { os << " "; } } } int main(int argc, char* argv[]) { Input* input = parseInput(std::cin); if(input->getT() & 0x01) { printInputReversed(input, std::cout); } else { printInput(input, std::cout); } std::cout << std::endl; return 0; } |
English