Cod sursa(job #312771)

Utilizator Pestisor_auriuVictor Movila Pestisor_auriu Data 6 mai 2009 22:28:11
Problema Tablete Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.77 kb
#include<stdio.h>
int main ()
{
freopen("tablete.in","r",stdin);
freopen("tablete.out","w",stdout);
int c=1,pp,n,k,i,j,r;
scanf("%d",&n);
scanf("%d",&k);
if(n%2==0&&k%2==0)
for(i=1;i<=n;i++)
{for(j=1;j<=n;j++)
 {printf("%d ",c);
	c++;}
printf("\n");}
else
if(n%2!=0&&k%2==0)
{ c=0; i=1;  pp=3;  r=1;
while(i!=n*n+1)
{if(c==0)
 {if(n==r&&pp!=3)
	{printf("%d",i);
	 if(i!=n*n)
	 i++;
	 printf("\n");
	 c=i;
	 i++;
	 r=1;
	 pp=0;}
	else
	{printf("%d ",i);
	 i++;
	 pp=0;
	 r++;}}
 else
	if(pp==1)
	{printf("%d ",c);
	 printf("%d ",i);
	 i++;
	 pp=0;
	 r=r+2;}
	else
	{if(r==n)
	 {printf("%d",i);
		printf("\n");
		printf("%d ",c);
		i++;
		r=2;
		c=0;
		pp=1;}
	 else
	 {printf("%d ",i);
		i++;
		r++;}
	 }
	} }
else

return 0;
}