这个围城怎么编??
2 2 2 22 1 1 2
2 1 1 2
2 2 2 2
扩展到N*N
#include<stdio.h>
#define abs(n) ((n)>0?(n):-(n))
#define max(x,y) ((x)>(y)?(x):(y))
#define num(n,i,j) (max(abs(2*(n)-2*(i)+1),abs(2*(n)-2*(j)+1))+1)/2
main(){
int n,i,j;
for(;;){
scanf(\"%d\",&n);
if(n<=0) break;
for(i=1;i<=2*n;i++){
for(j=1;j<=2*n;j++) printf(\"%4d\",num(n,i,j));
printf(\"\n\");
}
}
}
稍微修改下:
#include<stdio.h>
#define abs(n) ((n)>0?(n):-(n))
#define max(x,y) ((x)>(y)?(x):(y))
#define num(n,i,j) (int)(max(abs((n)-(i)+0.5),abs((n)-(j)+0.5))+0.6)
main(){
int n,i,j;
for(;;){
scanf(\"%d\",&n);
if(n<=0) break;
for(i=1;i<=2*n;i++){
for(j=1;j<=2*n;j++) printf(\"%4d\",num(n,i,j));
printf(\"\n\");
}
}
}
#include"stdio.h"
main()
{
int i,j;
int n;
input:
printf("Input n:");
scanf("%d",&n);
for(i=1;i<=2*n;i++)
{
for(j=1;j<=2*n;j++)
{
if(aabs(2*j,2*n+1)<=aabs(2*i,2*n+1))
printf("%d",(aabs(2*i,2*n+1)+1)/2);
if(aabs(2*i,2*n+1)<aabs(2*j,2*n+1))
printf("%d",(aabs(2*j,2*n+1)+1)/2);
}
printf("\n");
}
goto input;
}
int aabs(int a,int b)
{
if(a>b)
return (a-b);
else
return (b-a);
}