Pagini recente » Cod sursa (job #2484659) | Cod sursa (job #2822074) | Cod sursa (job #2718406) | Cod sursa (job #2483026) | Cod sursa (job #1936090)
#include <fstream>
using namespace std;
ifstream fin ("tablete.in");
ofstream fout ("tablete.out");
int n, k;
int main()
{
fin >> n >> k;
if (k % 2 == 0)
{
int loc = k * n, a = 0;
for (int i = 1; i <= n; i++)
{
a = (i - 1)*k;
for (int j = 1; j <= k; j++)fout << a + j << ' ';
for (int j = k + 1; j <= n; j++)fout << ++loc << ' ';
fout << '\n';
}
}
else if (/*n%2 == 0 && */k % 2 == 1)
{
int loc = n * k, a = 0;
for (int i = 1; i <= n; i++)
{
a = (i - 1)*k;
if (i % 2 == 1)
{
for (int j = 1; j < k; j++)fout << a + j << ' ';
fout << a + k + 1 << ' ';
}
else
{
fout << a << ' ';
for (int j = 2; j <= k; j++)fout << a + j << ' ';
}
for (int j = k + 1; j <= n; j++)fout << ++loc << ' ';
fout << '\n';
}
}
return 0;
}