using System; using System.Collections.Generic; using System.Text;
namespaceJose { classProgram { publicint[] Jose(int total, int start, int num) { int i; int j; int k; int[] count; //记录出队列的顺序 int[] people; //记录玩家编号 j = 0; k = 0; count = newint[total]; people = newint[total + 1]; for (i = 0; i < total; i++) //给玩家编号 { people[i] = i; }
for (i = total; i > 1; i--) { start = (start + num - 1) % i; if (start == 0) start = i; //找到出队玩家 count[k++] = people[start]; //记录出队玩家 for (j = start + 1; j <= i; j++) people[j - 1] = people[j]; //玩家出队,调整剩余玩家 }
count[k] = people[1]; return count; }
staticvoidMain(string[] args) { Program game = new Program(); int[] result = game.Jose(9, 0, 5); foreach (int o in result) { Console.WriteLine("编号为: " + o + " 的玩家出队"); }