View Code of Problem 80

#include <stdio.h>
using namespace std;
int main(){
	int n;
	while( ~scanf("%d", &n) && n!=0 ){
		int a[n];
		int i=0,j=0,k=0;
		for( i=1; i<=n; i++ ){
			a[i] = 1;
		}
		int cnt=0;
		i=1;
		while( cnt< n ){
			if( a[i]==1) j++;
			if( j==3 ){
				k = i;
				a[i]=0;
				cnt++;
				j= 0;
				
			}
			i++;
			if( i==n+1 ){
				i=0;
			}
		}
		printf("%d\n", k );
		
	}

	return 0;
	
}

Double click to view unformatted code.


Back to problem 80