点击打开链接
//蛇形填数
#include <iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn=100+5;
const char *str="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char field[maxn][maxn];
int main()
{
int r,c;
while(scanf("%d%d",&r,&c)==2)
{
for(int i=0;i<r;i++)
for(int j=0;j<c;j++)
field[i][j]='@';
int x,y;
field[x=0][y=0]='A';
int tot=1;
while(tot<r*c)
{
while(y+1<c&&field[x][y+1]=='@') { field[x][++y]=str[(tot)%26]; tot++; }
while(x+1<r&&field[x+1][y]=='@') { field[++x][y]=str[(tot)%26]; tot++; }
while(y-1>=0&&field[x][y-1]=='@') { field[x][--y]=str[(tot)%26]; tot++; }
while(x-1>=0&&field[x-1][y]=='@') { field[--x][y]=str[(tot)%26]; tot++; }
}
for(int i=0;i<r;i++)
{
cout<<" ";
for(int j=0;j<c;j++)
{
cout<<field[i][j]<<" ";
}
cout<<endl;
}
}
return 0;
}
poj 3752 字母旋转游戏(蛇形填数)
最新推荐文章于 2021-02-13 05:08:16 发布