标题:求一个用约瑟夫环,也就是循环代码的一个题,其他同学请绕行
取消只看楼主
薇儿2333
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2018-4-19
结帖率:66.67%
已结贴  问题点数:18 回复次数:0 
求一个用约瑟夫环,也就是循环代码的一个题,其他同学请绕行
This May, a group of exchange students come to HIT. They would like to play a game. Firstly, they stand in a circle. Then they choose the Mth student as the first and count off one by one (for example, the first calls 1,the second calls 2 and so on). Every time when one calls number K, he will be out of the circle, and the rest continue the game and his next student will be the new first. The last one to leave the circle will be the winner of the round. Now the question is who will be winner of each round?

Hint:You can solve the problem with a circular linked list.
Input and output data format:
Input
First line: a number N indicates the number of the students;
The following n lines: each line is a name which is a string without any digit whose maximum length is 20.
The next lines:each line shows one round and there are two numbers M and K.
Output
For each round, you need to output one line represents the name of the winner in the round.
Sample:
Input
4
Tom
Jack
Sol
Free
2 3
3 2

Output

Jack

Sol

Interpretation:
The first round:

Jack 1, Sol 2, Free 3,     Free out;

Tom 1,Jack 2, Sol 3,      Sol out;

Tom 1,Jack 2, Tom 3,    Tom out;

Jack is the winner.
搜索更多相关主题的帖子: the first and one output 
2018-05-17 00:29



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-486997-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.616696 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved