Cod sursa(job #1706237)

Utilizator moise_alexandruMoise Alexandru moise_alexandru Data 21 mai 2016 22:46:19
Problema Tablete Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.71 kb
#include <iostream>
#include <fstream>
#include <cassert>
using namespace std;
ifstream in("tablete.in");
ofstream out("tablete.out");
const int maxn = 1005;
int M[maxn][maxn];
int main()
{
    int n, k;
    in >> n >> k;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++)
            M[i][j] = (i - 1) * n + j;
    if(n % 2 == 0 && k % 2 == 0)
    {
        for(int i = 1; i <= n; i++, out << "\n")
            for(int j = 1; j <= n; j++)
                out << M[i][j] << " ";
    }

    if(n % 2 == 0 && k % 2 == 1)
    {
        for(int i = 1; i <= n; i++)
            for(int j = k; j <= n - 1; j++)
                swap(M[i][j], M[i][j+1]);
        for(int i = 1; i < n; i++)
            swap(M[i][n], M[i+1][1]);
        for(int i = 1; i <= n; i++, out << "\n")
            for(int j = 1; j <= n; j++)
                out << M[i][j] << " ";
    }

    if(n % 2 == 1 && k % 2 == 0)
    {
        assert(false);
        for(int i = 2; i <= n; i = i + 2)
            for(int j = k; j < n; j++)
                swap(M[i][j], M[i][j+1]);
        for(int i = 2; i <= n; i = i + 2)
            swap(M[i][n], M[i+1][1]);
        for(int i = 1; i <= n; i++, out << "\n")
            for(int j = 1; j <= n; j++)
                out << M[i][j] << " ";
    }

    if(n % 2 == 1 && k % 2 == 1)
    {
        assert(false);
        for(int i = 1; i <= n; i = i + 2)
            for(int j = k; j < n; j++)
                swap(M[i][j], M[i][j+1]);
        for(int i = 1; i < n; i = i + 2)
            swap(M[i][n], M[i+1][1]);
        for(int i = 1; i <= n; i++, out << "\n")
            for(int j = 1; j <= n; j++)
                out << M[i][j] << " ";
    }
    return 0;
}