View Code of Problem 80

#include<stdio.h>
int main()
{
	int n,i,cnt,m,*p,a[100000];
	while( scanf("%d",&n)!=EOF && n!=0)
	{
		p = a;
		for( i=0; i<n;i++ ) 
		{
			*(p+i) = i+1;
		//	printf("%d %d\n",a[i]),p;
		}
		i = 0;
		cnt = 0;
		m = 0;
		while( m<n-1 )//m±íʾ³ö¾Ö 
		{
			if(*(p+i)!=0)
			{
				cnt++;
			}
			if( cnt == 3 )
			{
				*(p+i) = 0;
				cnt = 0;
				m++;
			}
			i++;
			if( i==n )
			{
				i=0;
			}
		}
		while(*p==0){
			p++;
		}
		  printf("%d\n",*p);		  
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 80