View Code of Problem 80

#include<stdio.h>

int main()
{
	int member[100]={0};
	int n;
	int count;
	scanf("%d", &n);
	while(n > 0)
	{
		int pos = 0;
		count = n;
		for(int i = 0; i < n; i++)
			member[i] = i+1;
		if(n == 1)
		{
			printf("%d", member[pos]);
			continue;
		}
		while(count > 1)
		{
			for(int i = 0; i < 3; i++, pos++)
			{
				pos = pos % n;
				if(member[pos] == 0)
					i--;
			}
			member[--pos] = 0;
			count--; 
			if(count == 1)
			{
				for(int j = 0; j < n; j++)
					if(member[j] != 0)
						printf("%d\n", member[j]);
				break;
			}
		}
		scanf("%d", &n);
	}
}

Double click to view unformatted code.


Back to problem 80