TORONTO KIDS COMPUTER CLUB | Tuesday 17:00 Python Practice – 22.02.28.
20311
post-template-default,single,single-post,postid-20311,single-format-standard,ajax_fade,page_not_loaded,,qode-theme-ver-7.6.2,wpb-js-composer js-comp-ver-6.8.0,vc_responsive

Tuesday 17:00 Python Practice – 22.02.28.

12 Feb Tuesday 17:00 Python Practice – 22.02.28.

Question:

Try to use the queue class to implement a general simulation of Hot Potato. Our program will input a list of names and a number, we call it “num,” to be used for counting. It will return the name of the last person remaining after repetitive counting by num.

To simulate the circle, we will use a queue. Assume that the child holding the potato will be at the front of the queue. Upon passing the potato, the simulation will simply dequeue and then immediately enqueue that child, putting her at the end of the line. She will then wait until all the others have been at the front before it will be her turn again.

After num dequeue/enqueue operations, the child at the front will be removed permanently and another cycle will begin. This process will continue until only one name remains.

Input Specification:
The first line is children’s names separated by space, second line is the num

Output Specification:
The name of the the last child


Sample Input:
Bill David Susan Jane Kent Brad
7

Sample Output:
Susan
No Comments

Sorry, the comment form is closed at this time.