# Cod sursa(job #24194)

Utilizator Data 1 martie 2007 21:21:36 Oras 100 cpp done Arhiva de probleme 1.31 kb

#include<stdio.h>
#include<string.h>
#define Nmax 201

int n;

void solveimpar()
{
char cimp[Nmax][Nmax];

int i,j;

strcpy(cimp[1]+1,"010");
strcpy(cimp[2]+1,"001");
strcpy(cimp[3]+1,"100");

for( i=4 ; i <= n ; i += 2 )
{
cimp[i][i+1]='1';
cimp[i+1][i]='0';
for( j = 1 ; j < i ; j ++ )
{
cimp[j][i]='1'; cimp[i][j]='0';
cimp[i+1][j]='1'; cimp[j][i+1]='0';
}
}

for(i=1;i<=n;i++)
{
cimp[i][i]='0';
for(j=1;j<=n;j++)
printf("%c",cimp[i][j]);
printf("\n");
}

}

void solvepar()
{
char cpar[Nmax][Nmax];

int i,j;

if( n ==4 ) { printf("-1\n");return; }

strcpy(cpar[1]+1,"010001");
strcpy(cpar[2]+1,"001101");
strcpy(cpar[3]+1,"100101");
strcpy(cpar[4]+1,"100010");
strcpy(cpar[5]+1,"111000");
strcpy(cpar[6]+1,"000110");

for(i=7 ; i<= n ; i+=2 )
{
cpar[i][i+1]='1';
cpar[i+1][i]='0';
for( j = 1 ; j < i ; j ++ )
{
cpar[j][i]='1'; cpar[i][j]='0';
cpar[i+1][j]='1'; cpar[j][i+1]='0';
}
}

for(i=1;i<=n;i++)
{
cpar[i][i]='0';
for(j=1;j<=n;j++)
printf("%c",cpar[i][j]);
printf("\n");
}

}

int main()
{
freopen("oras.in","r",stdin);
freopen("oras.out","w",stdout);

scanf("%d",&n);

if( n%2 ) solveimpar();
else solvepar();

return 0;
}