Cod sursa(job #2612531)

Utilizator andreic06Andrei Calota andreic06 Data 9 mai 2020 10:30:57
Problema Tablete Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <iostream>
#include <fstream>

using namespace std;
const int N = 1e3;

int a[N+1][N+1];

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

int main()
{
   int n, k;
   int i, j;

   fin >> n >> k;

   int nr = 1;
   for ( i = 1; i <= n; i ++ )
      for ( j = 1; j <= k; j ++ )
         a[i][j] = nr ++;

   for ( i = 1; i <= n; i ++ )
      for ( j = k + 1; j <= n; j ++ )
         a[i][j] = nr ++;

   if ( k % 2 == 1 ) {
     int aux;

     for ( i = 1; i <= n; i += 2 ) {
        aux = a[i][k];
        a[i][k] = a[i+1][1];
        a[i+1][1] = aux;
     }
   }

   for ( i = 1; i <= n; i ++ ) {
      for ( j = 1; j <= n; j ++ ) {
         fout << a[i][j] << ' ';
      }
      fout << '\n';
   }
    return 0;
}