poj3752
简单题
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
#define maxn 555
char st[maxn][maxn];
int dir[4][2] =
{
{ 0, 1 },
{ 1, 0 },
{ 0, -1 },
{ -1, 0 } };
int n, m;
bool ok(int x, int y)
{
if (x < 0 || y < 0 || x >= n || y >= m)
return false;
if (st[x][y] != 0)
return false;
return true;
}
int main()
{
//freopen("t.txt", "r", stdin);
scanf("%d%d", &n, &m);
int x = 0;
int y = 0;
int d = 0;
memset(st, 0, sizeof(st));
for (int i = 0; i < m * n; i++)
{
st[x][y] = i % 26 + 'A';
if (!ok(x + dir[d][0], y + dir[d][1]))
d = (d + 1) % 4;
x += dir[d][0];
y += dir[d][1];
}
for (int i = 0; i < n; i++)
{
for (int j= 0; j < m; j++)
printf(" %c", st[i][j]);
putchar('\n');
}
return 0;
}
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
#define maxn 555
char st[maxn][maxn];
int dir[4][2] =
{
{ 0, 1 },
{ 1, 0 },
{ 0, -1 },
{ -1, 0 } };
int n, m;
bool ok(int x, int y)
{
if (x < 0 || y < 0 || x >= n || y >= m)
return false;
if (st[x][y] != 0)
return false;
return true;
}
int main()
{
//freopen("t.txt", "r", stdin);
scanf("%d%d", &n, &m);
int x = 0;
int y = 0;
int d = 0;
memset(st, 0, sizeof(st));
for (int i = 0; i < m * n; i++)
{
st[x][y] = i % 26 + 'A';
if (!ok(x + dir[d][0], y + dir[d][1]))
d = (d + 1) % 4;
x += dir[d][0];
y += dir[d][1];
}
for (int i = 0; i < n; i++)
{
for (int j= 0; j < m; j++)
printf(" %c", st[i][j]);
putchar('\n');
}
return 0;
}