static void Main(string[] args)
{
//保存移走的人的個數
int RemoveCount = 0;
//保存每一個人讀出的數字
int ReadCount = 0;
int[] personNum = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };遞歸
while (true)
{
for (int i = 0; i < personNum.Length; i++)
{
//表示沒有移除的數據
if (personNum[i] != -1)
{
//數字加1
ReadCount++;
if (ReadCount % 3 == 0)
{
//設置爲移除-1
Console.WriteLine(personNum[i]+"號移除");
personNum[i] = -1;
//移除的個數
RemoveCount++;
if (RemoveCount >= 16)
{
break;
}
}
}
}
if (RemoveCount >= 16)
{
break;
}
}
//最後輸出一個數字
for (int i = 0; i < personNum.Length; i++)
{
if (personNum[i] != -1)
{
Console.WriteLine("最後一我的原來的編號是"+personNum[i]);
break;數學
}
}
}string