Cod sursa(job #1433167)

Utilizator beta226Claudia Gacichevici beta226 Data 9 mai 2015 15:02:11
Problema Tablete Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.04 kb
#include <iostream>
#include <fstream>

using namespace std;
const int Nmax=1000;
int a[Nmax+1][Nmax+1];

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

int main()
{
    int n,k,i,j,p=1;
    fin>> n >>k;
    for (i=1;i<=n;i++)
        for(j=1;j<=n;j++) a[i][j]=0;

    for (i=1;i<=n;i++)
        for(j=1;j<=k;j++)
            {
            if ((j==k)&&(p%2==1)) {a[i][j]=p+1;
                                   if (i<n)
                                        a[i+1][1]= p;
                                   else
                                        a[1][k+1]=p;
                                   p=p+2;}
            else
                    if (a[i][j]==0)
                        {a[i][j]= p;
                        p++ ;}
            }
    for (i=1;i<=n;i++)
        for (j=k+1;j<=n;j++)
    {
       if (a[i][j]==0)
            {a[i][j]=p;
            p++;}
    }
    for (i=1;i<=n;i++)
        {for(j=1;j<=n;j++)
            fout <<a[i][j]<< " ";
        fout<<endl;
        }
    return 0;
}