Cod sursa(job #2099239)
| Utilizator | Data | 4 ianuarie 2018 11:23:30 | |
|---|---|---|---|
| Problema | Tablete | Scor | 90 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 1.95 kb |
#include <fstream>
using namespace std;
ifstream fin("tablete.in");
ofstream fout("tablete.out");
int n,k,i,j,a[1001][1001];
int main()
{
fin >> n >> k;
if (k%2 == 0)
{
int contor = 1;
for (i=1; i<=n; i++)
for (j=1; j<=k; j++)
a[i][j] = contor, contor++;
for (i=1; i<=n; i++)
for (j=k+1; j<=n; j++)
a[i][j] = contor, contor++;
for (i=1; i<=n; i++)
{
for (j=1; j<=n; j++)
fout << a[i][j] << " ";
fout << "\n";
}
}
else
{
int contor = 0;
for (i=1; i<n; i++)
for (j=1; j<=k; j++)
{
contor++;
if (a[i][j] == 0)
{
if (j < k)
a[i][j] = contor;
else
if (contor % 2 == 1)
{
a[i+1][1] = contor;
a[i][j] = contor+1;
}
else
a[i][j] = contor;
}
}
for (j=1; j<k; j++)
{
contor++;
if (a[n][j] == 0)
a[n][j] = contor;
}
if ((contor+1)%2 == 0)
{
contor++;
a[n][k] = contor;
}
else
{
contor++;
a[1][k+1] = contor;
contor++;
a[n][k] = contor;
}
for (i=1; i<=n; i++)
for (j=k+1; j<=n; j++)
if (a[i][j] == 0)
{
contor++;
a[i][j] = contor;
}
for (i=1; i<=n; i++)
{
for (j=1; j<=n; j++)
fout << a[i][j] << " ";
fout << "\n";
}
}
return 0;
}
