View Code of Problem 80

#include<stdio.h>
#include<math.h>
#include <string.h>
#define Max 1000
#include <stdio.h>
int main()
{
	
	int a[50],i,n,count ,flag=0;
  while(scanf("%d",&n)!=EOF)
  {
	
	count=n;
	for(i=1;i<=n;i++)
	   a[i]=1;//所有人都在圈内,为1 
	for(i=1; ;i++)
	{
		if(i==n+1)
		   i=1;//如果i超出了n个人,让她回到1 
		   
		if(a[i]!=0)  flag++;
		else  continue;
		
		if(flag%3==0)
		{
			a[i]=0;
			count--;
		}
		
		if(count==1)//只剩一个人在圈里 
		   break;
	}
	
	for(i=1;i<=n;i++)
	  if(a[i]!=0)
	     printf("%d",i);	
  }
	
	return 0;
	
}

Double click to view unformatted code.


Back to problem 80