谢尔顿、伦纳德、佩妮、拉杰什和霍华德正在排队购买“双可乐”饮料自动售货机;队列中没有其他人。队列中的第一个(谢尔顿)买了一罐,喝了它并翻倍!由此产生的两个谢尔顿将排在队列的末尾。然后队列中的下一个(伦纳德)买了一个罐头,喝了它,然后作为两个伦纳德走到队列的最后,依此类推。这个过程无限期地继续下去。
例如,佩妮喝了第三罐可乐,队列看起来像这样:拉杰什、霍华德、谢尔顿、谢尔顿、伦纳德、伦纳德、佩妮、佩妮。
编写一个程序,打印一个将喝第 n 罐的人的名字。
请注意,在一开始,队列看起来像这样:谢尔顿、伦纳德、佩妮、拉杰什、霍华德。
Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum.
1
Sheldon
6
Sheldon
1802
Penny
1
Sheldon