View Code of Problem 80

#include<iostream>
#include<cstdio>
#include<string.h>

int p[1000];
using namespace std;

int main()
{
	int n, count;
	while(scanf("%d", &n) != EOF)
	{
		int pos = 0, k = 1;
		memset(p, 0, sizeof(p));
		if(n == 0)
			break;
		count = n;
		while(count != 1)
		{
			pos++;
			pos %= n;
			while(p[pos] == 1)
			{
				pos++;
				pos %= n;
			}
			k++;
			if(k == 3)
			{
				p[pos] = 1;
				k = 0;
				count--;	
			}
		}
		for(pos = 0; pos < n; pos++)
			if(p[pos] == 0)
				break;
		printf("%d\n", pos+1);
	 } 
	return 0;
}

Double click to view unformatted code.


Back to problem 80