📄 ch23-14.c
字号:
#define N 13
#include<stdio.h>
#include<conio.h>
struct person
{
int number; /*its order in the original circle */
int nextp; /*record its next person */
};
struct person link[N+1]; /*link[0] for no use*/
void main()
{
int i,count,next;
/*count for 12 persons,and next for the person not out of circle yet */
for (i=1;i<=N;i++)
{
link[i].number=i; /*numbering each person*/
if(i==N)
link[i].nextp=1;
else
link[i].nextp=i+1; /*numbering each next person*/
}
printf("\nThe sequence out of the circle is:\n");
for(next=1,count=1;count<N;count++) /*count until 12 persons*/
{
i=1;
while (i!=3) /*i counts 1,2,3 */
{
do /*skip the ones whose numbers are zero */
{
next=link[next].nextp;
}while(link[next].number==0); /*end of do*/
i++;
}
printf("%3d ",link[next].number);
link[next].number=0; /*indicate out of circle already*/
do /*start from the ones whose numbers are not zero next time*/
{
next=link[next].nextp;
}while(link[next].number==0);
}
printf("\n\nThe betrayer is:");
for(i=1;i<=N;i++)
if(link[i].number)
printf("%3d\n",link[i].number);
getch();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -