[ create a new paste ] login | about

Link: http://codepad.org/3xwQftbR    [ raw code | output | fork ]

C, pasted on Dec 11:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int toilet[3005]={0};
int main() 
{
	int n,total,th;
	scanf("%d",&n);
	toilet[0]=1;
	while(n--)
	{
		int max = -1,sit;
		scanf("%d %d",&total,&th);
		toilet[total+1]=1;
		while(th--)
		{
			max = -1;
			for(int i = 1 ; i <= total ; i++)
			{
				if(toilet[i] == 0)
				{
					int left = 0,right =0;
					while(toilet[i-1-left]==0&&toilet[i+1+right]==0)
					{
						left++;
						right++;
					}
					if(left>max) 
					{
						max = left;
						sit = i;
					}
				}
			}
			toilet[sit] = 1;
		}
		printf("%d\n",sit);
		for(int i = 1 ; i <= total+1; i++)
		{
			toilet[i] = 0;
		}
	}
	return 0;
}


Output:
1
2
3
In function 'main':
Line 18: error: 'for' loop initial declaration used outside C99 mode
Line 38: error: 'for' loop initial declaration used outside C99 mode


Create a new paste based on this one


Comments: