Cod sursa(job #2257387)

Utilizator nimicLeoveanu Mihaita Alexandru nimic Data 9 octombrie 2018 23:52:41
Problema Tablete Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.38 kb
#include <fstream>
using namespace std;
ifstream fin("tablete.in");
ofstream fout("tablete.out");

int n,m,k,v[1006][1006],i,j;

int main()
{
    fin>>n>>m;
    if(n%2==0&&m%2==0)for(i=1;i<=n;i++)for(j=1;j<=n;j++) {v[i][j]=n*(i-1)+j;}
    if(n%2==0&&m%2!=0)
    {
        for(i=1;i<=n;i++)
            v[i][1]=i;
        k=n*n-n+1;
        for(i=1;i<=n;i++)
        {
                v[i][n]=k;
                k++;
        }
        k=n+1;
        for(i=1;i<=n;i++)
            for(j=2;j<=n-1;j++)
            {
                v[i][j]=k;
                k++;
            }
    }
    if(n%2!=0 && m%2==0)
    {
        for(i=1;i<=n;i++)
            v[i][1]=i;
        for(i=2;i<=n;i++)
            v[n][i]=n+i-1;
        k=2*n;
        for(i=1;i<=n-1;i++)
            for(j=2;j<=n;j++)
            {
                v[i][j]=k;
                k++;
            }
    }
    if(n%2!=0&&m%2!=0)
    {
        while(1)
        {
        }
        for(i=1;i<=n;i++)
            v[i][1]=i;
        for(i=2;i<=n-1;i++)
            v[n][i]=n+i-1;
        v[n][n]=n*n;
        k=n+n-1;
        for(i=1;i<=n-1;i++)
            for(j=2;j<=n;j++)
            {
                v[i][j]=k;
                k++;
            }
    }
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=n;j++)
            fout<<v[i][j]<<" ";
        fout<< endl;
    }
    return 0;
}