Cod sursa(job #2031546)
| Utilizator | Data | 3 octombrie 2017 13:31:16 | |
|---|---|---|---|
| Problema | Tablete | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 1.45 kb |
#include <iostream>
#include <fstream>
using namespace std;
int n,k;
ifstream fin("tablete.in");
ofstream fout("tablete.out");
int main()
{
int i,j,x;
fin>>n>>k;
if(n%2==0&&k%2==0)
{
x=1;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
fout<<x++<<" ";
fout<<"\n";
}
}
else
if(n%2&&k%2==0)
{
x=n+1;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
if(j==0)
fout<<i+1<<" ";
else
fout<<x++<<" ";
fout<<"\n";
}
}
else
if(n%2==0&&k%2)
{
x=n+1;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
if(j==0)
fout<<i+1<<" ";
else if(j==n-1)
fout<<n*n-n+i+1<<" ";
else
fout<<x++<<" ";
fout<<"\n";
}
}
else
if(n%2&&k%2)
{
x=n;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
if(j==0&&i<n-1)
fout<<i+1<<" ";
else if(i==n-1)
fout<<n*n-n+j<<" ";
else if(i==n-2&&j==n-1)
fout<<n*n<<" ";
else
fout<<x++<<" ";
fout<<"\n";
}
}
return 0;
}
