源程序
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp4
{
class Program
{
static void Main(string[] args)
{
int[] a = new int[10];
int sum = 10;//共有10个人;
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 == 3)
{
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");
}
}
}
感谢网友
原文链接
https://zhidao.baidu.com/question/1925055306221642467.html