Cod sursa(job #1936090)

Utilizator ancabdBadiu Anca ancabd Data 22 martie 2017 20:30:55
Problema Tablete Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.05 kb
#include <fstream>

using namespace std;

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

int n, k;
int main()
{
    fin >> n >> k;
    if (k % 2 == 0)
    {
        int loc = k * n, a = 0;
        for (int i = 1; i <= n; i++)
        {
            a = (i - 1)*k;
            for (int j = 1; j <= k; j++)fout << a + j << ' ';
            for (int j = k + 1; j <= n; j++)fout << ++loc << ' ';
            fout << '\n';
        }
    }
    else if (/*n%2 == 0 && */k % 2 == 1)
    {
        int loc = n * k, a = 0;
        for (int i = 1; i <= n; i++)
        {
            a = (i - 1)*k;

            if (i % 2 == 1)
            {
                for (int j = 1; j < k; j++)fout << a + j << ' ';
                fout << a + k + 1 << ' ';
            }
            else
            {
                fout << a << ' ';
                for (int j = 2; j <= k; j++)fout << a + j << ' ';
            }
            for (int j = k + 1; j <= n; j++)fout << ++loc << ' ';
            fout << '\n';
        }
    }
    return 0;
}