Cod sursa(job #1529642)

Utilizator Andrei_CotorAndrei Cotor Andrei_Cotor Data 21 noiembrie 2015 09:46:56
Problema Tablete Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.96 kb
#include <stdio.h>
using namespace std;
FILE *fi,*fo;
int x,n,i,j,k,A[1001][1001];
int main()
{
    fi=fopen("tablete.in","r");
    fo=fopen("tablete.out","w");
    fscanf(fi,"%d%d",&n,&k);
    x=0;
    for(i=1; i<=n; i++)
        for(j=1; j<=n; j++)
            A[i][j]=++x;
    if(k%2==0)
    {
        for(i=1; i<=n; i++)
        {
            for(j=1; j<=n; j++)
                fprintf(fo,"%d ",A[i][j]);
            fprintf(fo,"\n");
        }
    }
    else
    {
        for(i=1; i<=n; i+=2)
        {
            A[i+1][0]=A[i][1];
            A[i][1]=0;
            A[i+1][n+1]=A[i][n];
            A[i][n]=0;
        }
        for(i=1; i<=n; i++)
        {
            for(j=0; j<=n+1; j++)
            {
                if(A[i][j]!=0)
                {
                    fprintf(fo,"%d ",&A[i][j]);
                }
            }
            fprintf(fo,"\n");
        }
    }
    fclose(fi);
    fclose(fo);
    return 0;
}