Pagini recente » Cod sursa (job #1290316) | Cod sursa (job #2532298) | Cod sursa (job #1517531) | Cod sursa (job #318569) | Cod sursa (job #232309)
Cod sursa(job #232309)
#include<string.h>
#include<stdio.h>
#include<fstream.h>
FILE *f,*g;
int main()
{
f=fopen("tablete.in","r");
g=fopen("tablete.out","w");
long i,j,n,k,x,a[1001][1001],aux;
fscanf(f,"%d",&n);
fscanf(f,"%d",&k);
x=1;
for(i=1;i<=n;i++)
for(j=1;j<=k;j++)
{
a[i][j]=x;
x++;
}
for (i=1;i<=n;i++)
for (j=k+1;j<=n;j++)
{
a[i][j]=x;
x++;
}
if(k%2==1){
for(i=1;i<=n;i=1+2){ aux=a[i][k];
a[i][k]=a[i+1][1];
a[i+1][1]=aux;
}
if(n%2==1) { aux=a[n][k];
a[n][k]=a[1][k+1];
a[1][k+1]=aux;
}
}
for(i=1;i<=n;i++)
for(j=1;j<=k;j++)
fprintf(g,"%d",a[i][j]);
fclose(f);
fclose(g);
}