Cod sursa(job #3163352)

Utilizator eduardbuchmaneduardbuchman eduardbuchman Data 31 octombrie 2023 12:20:26
Problema Tablete Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.79 kb
#include <iostream>
#include <fstream>

using namespace std;
ifstream in("tablete.in");
ofstream out("tablete.out");
int tableta[1002][1002];
int main()
{
    int n, k;
    in >> n >> k;
    int nr = 0;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= k; j++)
            tableta[i][j] = ++nr;
    for(int i = 1; i <= n; i++)
        for(int j = k + 1; j <= n; j++)
            tableta[i][j] = ++nr;
    if(k&1){
        for(int i = 2; i <= n; i += 2)
            swap(tableta[i][1], tableta[i - 1][k]);
        if(n % 2 == 1){
            swap(tableta[n][k], tableta[1][k + 1]);
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            out << tableta[i][j] << " ";
        }
        out << "\n";
    }
    return 0;
}