View Code of Problem 80

#include<stdio.h>
#include<string.h>
#include<math.h>
int main()
{
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		if(n==0)
			break;
		int a[10000];
		int i,tmp,count=0;
		tmp=n;
		for(i=0;i<n;i++)
		{
			a[i]=i+1;
		}
		i=0;
		while(n>1)
		{
			if(a[i]!=0)
				count++;
			if(count==3)
			{
				a[i]=0;
				count=0;
				n--;
			}
			i++;
			if(i==tmp)
				i=0;
		}
		for(i=0;i<tmp;i++)
		{
			if(a[i]!=0)
				printf("%d\n",a[i]);
		}
	}
	return 0;
} 

Double click to view unformatted code.


Back to problem 80