Cod sursa(job #2001539)

Utilizator vladschillerVlad Radu Schiller vladschiller Data 17 iulie 2017 00:20:14
Problema Tablete Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.08 kb
#include <iostream>
#include <fstream>

using namespace std;
ifstream f("tablete.in");
ofstream g("tablete.out");
int mat[1000][1000],n,k;
bool npar,kpar;

void proc(bool npar,bool kpar)
{
    int curs=1;

        for(int i=0; i<n; i++)
            for(int j=0; j<k; j++)
            {
                mat[j][i]=curs;
                curs++;
            }
        for(int i=0; i<n; i++)
            for(int j=k; j<n; j++)
            {
                mat[j][i]=curs;
                curs++;
            }
    if(kpar==1)
    {
        for(int i=0;i<n-int(npar);i+=2)
        {
            int aux=mat[k-1][i];
            mat[k-1][i]=mat[0][i+1];
            mat[0][i+1]=aux;
        }
        if(npar)
        {
            int aux=mat[k-1][n-1];
            mat[k-1][n-1]=mat[k][0];
            mat[k][0]=aux;
        }
    }
}

int main()
{
    f>>n>>k;
    npar=bool(n%2);
    kpar=bool(k%2);
    proc(npar,kpar);
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<n; j++)
            g<<mat[j][i]<<' ';
        g<<'\n';
    }
    return 0;
}