Cod sursa(job #2181970)

Utilizator clara123Ghira Clara clara123 Data 21 martie 2018 23:11:26
Problema Tablete Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.94 kb
#include <fstream>
using namespace std;
ifstream fin ("tablete.in");
ofstream fout ("tablete.out");
int i,n,k,x,j,v[1010][1010];
int main (){
    fin>>n>>k;
    if(k%2==0){
        x=2;
        for(i=1;i<=n;i++)
            for(j=2;j<=n;j=j+2)
        {
                v[i][j]=x;
                x=x+2;
        }
        x=1;
        for(i=1;i<=n;i++)
            for(j=1;j<=n;j=j+2)
                {
                v[i][j]=x;
                x=x+2;
                }
    }
    else{
        x=2;
        for(i=1;i<=n;i++)
            for(j=1;j<=n;j=j+2)
        {
                v[i][j]=x;
                x=x+2;
                        }
        x=1;
        for(i=1;i<=n;i++)
            for(j=2;j<=n;j=j+2){
                v[i][j]=x;
                x=x+2;
            }
    }
    for(i=1;i<=n;i++){
        for(j=1;j<=n;j++)
            fout<<v[i][j]<<" ";
        fout<<"\n";
    }


    return 0;
}