poj3752

简单题

View Code
#include <iostream>
#include 
<cstdio>
#include 
<cstdlib>
#include 
<cstring>
using namespace std;

#define maxn 555

char st[maxn][maxn];
int dir[4][2=
{
01 },
10 },
0-1 },
-10 } };
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, 
0sizeof(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;
}
原文地址:https://www.cnblogs.com/rainydays/p/2105693.html