Cod sursa(job #2466528)

Utilizator ContNou1Cont nou 1 ContNou1 Data 2 octombrie 2019 14:56:38
Problema Tablete Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.97 kb
#include <iostream>
#include <fstream>

/**nume: Gheorghe David
 clasa: a10-a
 mail:[email protected]*/

using namespace std;

int main()
{
    ifstream fin("tablete.in");
    ofstream fout("tablete.out");

    int n,k,a[100][100],n2,b[100],x;
    fin>>n;
    fin>>k;
    n2=n*n;
    for(x=1; x<n2; x++)
        b[x]=x;
    x=1;
    for(int i=1 ; i<n ; i+=2)
        for(int j=1 ; j<n ; j+=2)
        {
            a[i][j]=b[x];
            x++;

        }
    for(int i=2 ; i<n ; i+=2)
        for(int j=2 ; j<n ; j+=2)
        {
            if(j==k)
            {
                if(b[x]%2==0)
                {
                    a[i][j]=b[x];
                    x++;
                }
                else
                    a[i][j]=b[x+1];
            }

        }
        for(int i=1 ; i<n ; i++)
        {
        for(int j=1 ; j<n ; j++)
            fout<<a[i][j]<<" ";
            fout<<endl;
        }

    return 0;
}