Cod sursa(job #490973)

Utilizator 6301263George 6301263 Data 8 octombrie 2010 23:10:53
Problema Dame Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.83 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,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)
	{
		for(l=1;l<k;l++)
			st[l]=st[l+1];
		st[k]=2;
	}
	a=k+1;
	for(i=1;i<=n;i+=2)
		st[++k]=i;
	if(n%12==3 || n%12==9)
	{
		for(i=a;i<k-1;i++)
			st[i]=st[i+2];
		st[k-1]=1;
		st[k]=3;
	}		
	
	else if(n%12==2)
	{
		st[a]=3;
		st[a+1]=1;
		for(i=a+2;i<k;i++)
			st[i]=st[i+1];
		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<<" "<<st[i]<<endl;
	}	
	}	
	return 0;
}