#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<Windows.h>
#include<stdio.h>
void taotai(int a[17],int count,int count1)
{
while (count1 != 1)
{
for (int i = 0; i < 17; i++)
{
count++;//count记录报数
if (count1 == 1) break;//剩下最后一人
if (count % 3 == 0 && a[i] != 0)
{
a[i] = 0;
count1--;//某人离开
}
}
}
}
void main()
{
int a[17];
int count = 0, count1 = 17;
for (int i = 0; i < 17; i++)
{
a[i] = i + 1;//确定每个人的位置(编号)
count++;//count记录报数
if (count%3 == 0)
{
a[i] = 0;
count1--;//某人离开
}
}
taotai(a,count,count1);
for (int j = 0; j < 17; j++)//打印剩下一人的位置
{
if (a[j] != 0)
printf("位置=%d", j);
}
system("pause");
}
有17个人围成一圈(编号为0~16),从第0号的人开始从1报数,凡报到3的倍数的人离开圈子,然后再数下去,直到最后只剩下一个人为止。问此人原来的位置是多少号?
最新推荐文章于 2023-03-19 15:09:14 发布