Cod sursa(job #2257362)

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

int main()
{
    int n,m,k,v[1006][1006],i,j;
    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)
    {
        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;
}