谁可以帮我改一下代码 代码如下
#include<stdio.h>int pass;
typedef struct Corner
{
int a;
int b;
int c;
int d;
};
typedef struct Array
{
int a[100][100];
int b[100][100];
int c[100][100];
int d[100][100];
};
int GetCorner(int m[100][100],int n)
{
int flag=0,mid=n/2+1;
if(n%2!=0){
if(mid%2!=0 || pass==0){
if(flag++==0){
Corner corner;
corner.a =m[0][0];
corner.b =m[0][n-1];
corner.c =m[n-1][0];
corner.d =m[n-1][n-1];
printf("%d %d %d %d\n",corner.a,corner.b,corner.c,corner.d);
}
if(flag++==1){
Corner corner;
corner.a =m[0][0];
corner.b =m[0][mid-1];
corner.c =m[mid-1][0];
corner.d =m[mid-1][mid-1];
printf("%d %d %d %d\n",corner.a,corner.b,corner.c,corner.d);
}
if(flag++==2){
Corner corner;
corner.a =m[0][mid-1];
corner.b =m[0][mid*2-2];
corner.c =m[mid-1][mid-1];
corner.d =m[mid-1][mid*2-2];
printf("%d %d %d %d\n",corner.a,corner.b,corner.c,corner.d);
}
if(flag++==3){
Corner corner;
corner.a =m[mid-1][0];
corner.b =m[mid-1][mid-1];
corner.c =m[mid-1][0];
corner.d =m[mid*2-2][mid-1];
printf("%d %d %d %d\n",corner.a,corner.b,corner.c,corner.d);
}
if(flag++==4){
Corner corner;
corner.a =m[mid-1][mid-1];
corner.b =m[mid-1][mid*2-2];
corner.c =m[mid*2-2][mid-1];
corner.d =m[mid*2-2][mid*2-2];
printf("%d %d %d %d\n",corner.a,corner.b,corner.c,corner.d);
}
}
}
return 0;
}
int Div_and_Put_Array(int A[100][100],int n)
{
Array sz;
int i,j;
while(n/2>1){
for(i=0;i<=n/2;i++)
for(j=0;j<=n/2;j++)
sz.a [i][j]=A[i][j];
GetCorner(sz.a ,n/2+1);
for(i=0;i<=n/2;i++)
for(j=n/2;j<=n-1;j++)
sz.b [i][j-n/2]=A[i][j];
GetCorner(sz.b ,n/2+1);
for(i=n/2;i<=n-1;i++)
for(j=0;j<=n/2;j++)
sz.c [i-n/2][j]=A[i][j];
GetCorner(sz.c ,n/2+1);
for(i=n/2;i<=n-1;i++)
for(j=n/2;j<=n-1;j++)
sz.d [i-n/2][j-n/2]=A[i][j];
GetCorner(sz.d ,n/2+1);
n/=2;
}
return 0;
}
int main()
{
int i,j,t,n;//n<=100
int Matrix[100][100];
while(scanf_s("%d",&n)){
if(n!=1){
t=1;
pass=0;
if(n%2!=0){
for(i=0;i<n;i++){
for(j=0;j<n;j++)
Matrix[i][j]=t++;
}
GetCorner(Matrix,n);
Div_and_Put_Array(Matrix,n);
}
else
printf("Can't get any square(s)!try another number!\n");
}
else
printf("Can't get any square(s)!try another number!\n");
}
return 0;
}