Pagini recente » Cod sursa (job #3270921) | Cod sursa (job #370021) | Cod sursa (job #368978) | Cod sursa (job #1414478) | Cod sursa (job #2257362)
#include <fstream>
using namespace std;
ifstream fin("tablete.in");
ofstream fout("tablete.out");
int main()
{
int n,m,k,v[1006][1006],i,j;
fin>>n>>m;
if(n%2==0&&m%2==0)for(i=1;i<=n;i++)for(j=1;j<=n;j++) {v[i][j]=n*(i-1)+j;}
if(n%2==0&&m%2!=0)
{
for(i=1;i<=n;i++) v[i][1]=i; k=n*n-n+1;
for(i=1;i<=n;i++) {v[i][n]=k;k++;};k=n+1;
for(i=1;i<=n;i++)for(j=2;j<=n-1;j++) {v[i][j]=k;k++;}
}
if(n%2!=0 && m%2==0)
{
for(i=1;i<=n;i++) v[i][1]=i; for(i=2;i<=n;i++) v[n][i]=n+i-1;
k=2*n;
for(i=1;i<=n-1;i++)for(j=2;j<=n;j++) {v[i][j]=k;k++;}
}
if(n%2!=0&&m%2!=0)
{
for(i=1;i<=n;i++) v[i][1]=i; for(i=2;i<=n-1;i++) v[n][i]=n+i-1; v[n][n]=n*n;
k=n+n-1;
for(i=1;i<=n-1;i++)for(j=2;j<=n;j++) {v[i][j]=k;k++;}
}
for(i=1;i<=n;i++){for(j=1;j<=n;j++) fout<<v[i][j]<<" "; fout<< endl;}
return 0;
}