//Dennis Matveyev for SER 2013 //Deck Shuffle /* Idea: do what it says! work it out on paper, translate into code In my case I went with marking top and bottom indices of the sub-decks. top deck index is always 0, but bottom may change depending on odd or even number of cards. Then, I just output the cards alternating from top and then bottom decks. If we had odd number of cards, then 1 card from top deck is left over, after 2 * (int)(n/2) cards are shuffled. If the top's index is lower than that of the first bottom card, we output our last card. */ #include #include #include using namespace std; int main() { int n; while (cin >> n && n > 0) { vector v(n); for (int i = 0; i < n; i++) cin >> v[i]; int top=0, bottom=n/2+n%2; for (int i = 0; i < n/2; i ++) { cout << v[top++] << endl; cout << v[bottom++] << endl; } if (top < n / 2 + n % 2); cout << v[top++] << endl; } return 0; }