标题:这个围城怎么编??
只看楼主
心剑菩提
Rank: 1
等 级:新手上路
帖 子:249
专家分:0
注 册:2007-5-17
 问题点数:0 回复次数:3 
这个围城怎么编??
2 2 2 2
2 1 1 2
2 1 1 2
2 2 2 2
扩展到N*N
搜索更多相关主题的帖子: 围城 
2007-05-23 08:48
Eastsun
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:32
帖 子:802
专家分:0
注 册:2006-12-14
得分:0 

#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\");
}
}
}

My BlogClick Me
2007-05-23 10:58
Eastsun
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:32
帖 子:802
专家分:0
注 册:2006-12-14
得分:0 

稍微修改下:


#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\");
}
}
}


My BlogClick Me
2007-05-23 11:18
a285028516
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2007-5-2
得分:0 

#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);
}

2007-05-23 16:51



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-141708-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.318196 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved