This topic ....
Want to test instructions.
10935 Throwing cards away I
Given is a ordered deck of n cards numbered 1 to n with card 1 at the top and card n at the bottom. The following operation is performed as long as there be at least, cards in the Deck:throw away the top card and move The card that's now on the top of the deck to the bottom of the deck. Your task is to find the sequence of discarded cards and the last, remaining card.
Input
Each line of input (except) contains a number n≤50. The last line contains ' 0 ' and this line should is processed.
Output
For each number from the input produce, lines of output. The first line presents the sequence of discarded cards, the second line reports the last remaining card. No Line would have leading or trailing spaces. See the sample for the expected format.
Sample Input
7
19
10
6
0
Sample Output
Discarded Cards:1, 3, 5, 7, 4, 2
Remaining Card:6
Discarded Cards:1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 4, 8, 12, 16, 2, 10, 18, 14
Remaining Card:6
Discarded Cards:1, 3, 5, 7, 9, 2, 6, 10, 8
Remaining Card:4
Discarded Cards:1, 3, 5, 2, 6
Remaining Card:4
My points (spit) analysis (Groove):
This topic, see test instructions will know is very suitable for use in STL deque container, because to frequent the ends of the end of the operation
Obvious water problem,, but I'm still going to die because of the format, because format, because the format to say three times
The final output is to be seen carefully discarded cards:1, 3, 5, 2, 6
There is a space after the colon, the number is preceded by a space, the number is followed by a comma, and no space after the comma ... If you want to put the topic over, you must carefully pay attention to these ah ...
My Code
1#include <cstdio>2#include <iostream>3#include <deque>4#include <vector>5 using namespacestd;6 7deque<int>cards;8vector<int>dis;9 intMain ()Ten { Onevector<int>:: iterator it; A voidChange (deque<int> &c); - intN; - while(cin >> N&&n! =0){ the dis.clear (); - cards.clear (); - for(inti =0; I < n; i++){ -Cards.push_back (i+1); +}//container fill sequence generation - for(inti =0; I < n1; i++) + Change (cards); Acout <<"Discarded cards:"; at for(it = Dis.begin (); It! = Dis.end (); it++){ -cout << *it; - if(It! = Dis.end ()-1) cout <<', '; - } -cout <<Endl; -cout <<"Remaining Card:"<<cards.front () <<Endl; in } - return 0; to + - } the * voidChange (deque<int> &c) $ {Panax Notoginseng Dis.push_back (C.front ()); - C.pop_front (); the inttemp =C.front (); + C.pop_front (); A C.push_back (temp); the}
View Code
UVa 1647-computer Transformation Problem Solving experience