Given in an ordered deck of n cards numbered 1 to n with card 1 at...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Given in an 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 are at least two cards in the deck: Throw away the top card and move the card that is 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. Each line of input (except the last) contains a number n ≤ 50. The last line contains 0 and this line should not be processed. For each number from the input produce two lines of output. The first line presents the sequence of discarded cards, the second line reports the last remaining card. Input The input file contains a non determinated number of lines. Each line contains an integer number. The last line contain the number zero (0). Output For each test case, print two lines. The first line presents the sequence of discarded cards, each number separated by a comma ',' and one blank space. The second line reports the last remaining card. No line will have leading or trailing spaces. See the sample for the expected format. 7 19 10 6 0 Input Samples Output Samples 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 Given in an 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 are at least two cards in the deck: Throw away the top card and move the card that is 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. Each line of input (except the last) contains a number n ≤ 50. The last line contains 0 and this line should not be processed. For each number from the input produce two lines of output. The first line presents the sequence of discarded cards, the second line reports the last remaining card. Input The input file contains a non determinated number of lines. Each line contains an integer number. The last line contain the number zero (0). Output For each test case, print two lines. The first line presents the sequence of discarded cards, each number separated by a comma ',' and one blank space. The second line reports the last remaining card. No line will have leading or trailing spaces. See the sample for the expected format. 7 19 10 6 0 Input Samples Output Samples 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
Expert Answer:
Answer rating: 100% (QA)
while True n intinput if n 0 break discarded queue for i in range 1 n 1 queueappendinti 7 while intl... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
The atmospheric pressures at the top and the bottom of a building are read by a barometer to be 96.0 and 98.0 kPa. If the density of air is 1.0 kg/m3, the height of the building is (a) 17 m (b) 20 m...
-
A large storage tank, open at the top and filled with water, develops a small hole in its side at a point 16.0 m below the water level. If the rate of flow from the leak is equal to 2.50 X 103m3/min,...
-
A deck of n cards numbered 1 through n is thoroughly shuffled so that all possible n! orderings can be assumed to be equally likely. Suppose you are to make n guesses sequentially, where the ith one...
-
On what date is CGT for 2020-21 normally due for payment?
-
Tasty Beverages began business in 2010 selling bottles of a thirst-quenching drink. Production for the first year was 104,000 bottles, and sales were 98,000 bottles. The selling price per bottle was...
-
How could third parties (i.e., neither debtors nor creditors) be guilty of bankruptcy fraud?
-
Correctly apply the rules for the order of operations to accurately compute the following: \((8-6)^{2} \times 100-\left((48 / 6-3)^{2}-4 \times 7 ight)\).
-
Owl-Eye Radiologists (OR) does various types of diagnostic imaging. Radiologists perform tests using sophisticated equipment. ORs management wants to compute the costs of performing tests for two...
-
For each of the following situations involving single amounts, solve for the unknown. Assume that interest is compounded annually. (= Interest rate, and n number of years) Note: Use tables, Excel, or...
-
Kat Ltd.s September balance sheet contains the following information: Cash.............................................................................$ 37,500 (dr) Accounts...
-
Whirly Corporations contribution format income statement for the most recent month is shown below: Total Per Unit Sales (8,600 units) $ 283,800 $ 33.00 Variable expenses 163,400 19.00 Contribution...
-
If you require a 25% return, what is maximum you should pay for the following investment? You buy a vending machine that will pay you the following cash flows: Year 1:$500 Year 2:$1,000 Year 3:$1,500...
-
Question 1 Liquid Hair's demand for bottles of shampoo was 10,500 units. The CEO asked the accountant about the expected cost for the sales-order activity. A new software had been installed, and the...
-
Financial management (please give a correct answer without using chat gpt) Using the information contained in the table below, answer the questions in the issue. Probability associated with each...
-
Describe the car you ended up choosing and why you chose that car (i.e. how does that car meet your needs)? Make sure to include all details about the car including the total price of the car and if...
-
11. At every point (x, y) on a certain curve, we have dy = 5. dx When x2, y attains a minimum value of 10. Find the equation of the curve. Page 2 of 6
-
Exercise 15-13 (Algo) Transactions in held-to-maturity, trading, and stock investments LO P1, P2, P4 a. On February 15, paid $190,000 cash to purchase GMI's 90-day short-term notes at par, which are...
-
Kims Konstructions has assembled the following data for a proposed straw-reinforced brick maker (SRBM): SRBM Cost: $26,000 Life: 5 years Revenue (p.a.) $11,000 Operating Expenses (p.a.) $3,000...
-
A set of 1000 cards numbered 1 through 1000 is randomly distributed among 1000 people with each receiving one card. Compute the expected number of cards that are given to people whose age matches the...
-
Prove Proposition 2.1 when (a) X and Y have a joint probability mass function; (b) X and Y have a joint probability density function and g(x, y) 0 for all x, y.
-
A total of n balls, numbered 1 through n, are put into n urns, also numbered 1 through n in such a way that ball i is equally likely to go into any of the urns 1, 2, . . . , i. Find (a) The expected...
-
\(45-6 \times 7^{3}\) Perform the indicated calculation.
-
\(72 \div 6+18\) Perform the indicated calculation.
-
\(6^{2} \times 5-13 \times 9^{2}\) Perform the indicated calculation.
Study smarter with the SolutionInn App