- using System;
- namespace heut
- {
- class Class1
- {
- public static void Main()
- {
- int[] a = new int[17];
- int sum = 17;//共有8个人;
- int k = 3;//每次数到3就退出;
- int count = 0;//记录退出的人数;
- int i = 0, j = 0;
- for (int m = 0; m < sum; m++)
- a[m] = 1;//数组元素全部初始化为1;
- while (count < sum - 1)
- {
- if (a[i] != 0)
- j++;
- if (j == k)
- {
- a[i] = 0;
- count++;
- j = 0;//重新开始,找下一个值!
- }
- i++;
- if (i == sum)
- i = 0;//实现环(即围成一圈);
- }
- for (int m = 0; m < sum; m++)
- if (a[m] != 0)
- Console.Write(m + 1 + "\\n");
- Console.ReadKey();
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/070820135007.html
来源: http://www.codesnippet.cn/detail/070820135007.html