您的位置:首页 > 其它

hdu 2153 仙人球的残影

2014-03-24 12:04 204 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2153

#include<iostream>
const int MAX=10;
int a[MAX][MAX];
using namespace std;
int main()
{
int n,x,y,tot=0;
while(scanf("%d",&n),n>=1&&n<=10)
{
memset(a,0,sizeof(a));
tot=a[x=0][y=0]=1;
while(tot<(n-1)*4)//只转一圈,4*n-4
{
while(y+1<n&&!a[x][y+1]) a[x][++y]=++tot;
while(x+1<n&&!a[x+1][y]) a[++x][y]=++tot;
while(y-1>=0&&!a[x][y-1]) a[x][--y]=++tot;
while(x-1>=0&&!a[x-1][y]) a[--x][y]=++tot;
}
for(x=0;x<n;x++)n
{
for(y=0;y<n;y++)
if(a[x][y]==0)
printf(" ");
else
printf("=",a[x][y]);
printf("\n");
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: