Pagini recente » Cod sursa (job #1059726) | Cod sursa (job #3032281) | Cod sursa (job #2399111) | Cod sursa (job #2919615) | Cod sursa (job #2254172)
#include <fstream>
#include <iostream>
using namespace std;
ifstream fin ("tablete.in");
ofstream fout ("tablete.out");
int n, k, i, j, x, r;
int main () {
fin >> n >> k;
if (k % 2 == 0 && n % 2 == 0) {
x = 1;
for (i = 1; i <= n; ++i) {
for (j = 1; j <= n; ++j) {
fout << x++ << ' ';
}
fout << "\n";
}
return 0;
}
x = 1;
for (i = 1; i <= n; ++i) {
for (j = 1; j <= n; ++j) {
if (j == 1 && r != 0) {
fout << r << ' ';
r = 0;
continue;
} else {
if (i == n - 1 && j == n) {
if (n % 2 == 1 && k % 2 ==0) {
fout << n * (n - 1) + 1;
} else {
fout << n * n;
}
} else {
if (j == k) {
if (x % 2 == 0) {
fout << x << ' ';
} else {
fout << x + 1 << ' ';
r = x++;
}
} else {
fout << x << ' ';
}
x++;
}
}
}
fout << "\n";
}
}