Cod sursa(job #311113)

Utilizator kam72anca knopf kam72 Data 2 mai 2009 16:03:37
Problema Tablete Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.31 kb
#include<stdio.h>
int main()
{
freopen("tablete.in","r",stdin);
freopen("tablete.out","w",stdout);
int n,k,i,j;
scanf("%d%d",&n,&k);
long c,aux;

if(n%2==0&&k%2==0)
	{c=1;
	for(i=1;i<=n;i++)
		{
		 for(j=1;j<=n;j++)
			{printf("%ld ",c); c++;}
		 printf("\n");
		}
	 }
else
 if(n%2==0&&k%2==1)

	for(i=1;i<=n;i++)
		{
		c=i-n;
		if(i%2==1)
			for(j=1;j<=n;j++)
				{c=c+n;
				 if(j==k)
					printf("%ld ",c-n+1);
				 else
					printf("%ld ",c);
				}
		else
			for(j=1;j<=n;j++)
			 {
				c=c+n;
				if(j==k-1)
					printf("%ld ",c+n-1);
				else
				 printf("%ld ",c);
				}
    printf("\n");
		}
	else
	 if(n%2==1&&k%2==0)
		{
		 c=1;
		 aux=1;c++;
		 for(i=1;i<=n;i++)
			{
			if(i%2==1)
				{
				printf("%ld ",aux);
				for(j=2;j<=n;j++)
					{printf("%ld ",c); c++;}
				}
			else
				{
				aux=c;
				c++;
				for(j=1;j<=n;j++)
					{printf("%ld ",c);
					 c++;}
				}
			printf("\n");
      }
		 }
	 else
		{
		 c=1;
		 aux=2;
		 for(i=1;i<n;i++)
			{

			 for(j=1;j<=n;j++)
				 {
					if(c==aux)
					 {c++;
						aux=aux+n+1;
						}

					printf("%ld ",c);
          c++;
					}

			 printf("\n");
			}
		 c=2;
		 for(j=1;j<=n-1;j++)
				{printf("%ld ",c);
				 c=c+n+1;
				 }
		 aux=n*n;
		 printf("%ld ",aux);
		 }

return 0;
}