Cod sursa(job #490967)

Utilizator 6301263George 6301263 Data 8 octombrie 2010 22:53:09
Problema Dame Scor 75
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.82 kb
#include<fstream>
#define NMax 1001
using namespace std;
int main()
{
	ifstream f ("dame.in");
	ofstream g ("dame.out");
	
	int a,n,i,k=0,l=0,st[NMax],aux;
	f>>n;
	if(n==1 ||n==2)
		g<<"1"<<endl<<"1 1";
	else if(n==3) 
		g<<"2"<<endl<<"1 1"<<endl<<"2 3";
	else
	{
	for(i=2;i<=n;i+=2)
		st[++k]=i;
	if(n%12==3 || n%12==9)
	{
		st[1]=0;
		st[++k]=2;
	}
	a=k+1;
	for(i=1;i<=n;i+=2)
		st[++k]=i;
	if(n%12==3 || n%12==9)
	{
		st[a]=0;
		st[a+1]=0;
		st[++k]=1;
		st[++k]=3;
	}
	else if(n%12==2)
	{
		st[a]=3;
		st[a+1]=1;
		st[a+2]=0;
		st[++k]=5;
	}
	else if(n%12==8)
		for(i=a;i<=k;i+=2)
		{
			aux=st[i];
			st[i]=st[i+1];
			st[i+1]=aux;
		}
	g<<n<<endl;
	for(i=1;i<=n;i++)
	{
		g<<i<<" ";
		if(st[i]==0)
		{
			l++;
			continue;
		}
		g<<st[i+l]<<endl;
	}	
	}	
	return 0;
}