求一个用约瑟夫环,也就是循环代码的一个题,其他同学请绕行
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.