Cod sursa(job #2314229)

Utilizator AndreosAndrei Otetea Andreos Data 8 ianuarie 2019 10:31:42
Problema Tablete Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.85 kb
#include <fstream>

using namespace std;
ifstream fin("tablete.in");
ofstream fout("tablete.out");
int a[1005][1005];
int main()
{
    int n,m,last=0,cnt=1,i,j;
    fin>>n>>m;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<m;j++)
        {
            if (last)
            {
                a[i][j]=last;
                last = 0;
            }
            else
                a[i][j]=cnt++;
        }
        if (cnt&1)
            last=cnt++;
        a[i][m]=cnt++;
    }
    for(i=1;i<=n;i++)
        for(j=m+1;j<=n;j++)
        {
            if(last)
            {
                a[i][j]=last;
                last = 0;
            }
            else
                a[i][j]=cnt++;
        }
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=n;j++)
            fout<<a[i][j]<<" ";
        fout<<"\n";
    }
    return 0;
}