#include <stdio.h>
#include <stdlib.h>
int M, N;
void fun(char *p, int m, int n, int c)
{
int i;
for (i = 0; i < n; i ++)
{
p[i] = 'A' + (c++)%26;
}
for (i = 1; i < m; i ++)
{
p[i*N+n-1] = 'A' + (c++)%26;
}
for (i = n-2; i > 0; i --)
{
if (m == 1) break;
p[(m-1)*N+i] = 'A' + (c++)%26;
}
for (i = m-1; i > 0; i --)
{
if (n == 1) break;
p[i*N] = 'A' + (c++)%26;
}
m -= 2;
if (m<=0) return;
n -= 2;
if (n<=0) return;
p = p + N+1;
fun(p, m, n, c);
}
int main(void)
{
int i, j;
char *p;
scanf("%d%d", &M, &N);
p =
(char *)malloc(M*N*sizeof(char));
fun(p, M, N, 0);
for (i = 0; i < M; i ++)
{
for (j = 0; j < N; j ++)
{
printf("%c", *(p+N*i+j));
}
printf("\n");
}
free(p);
}
办法是比较土,但能出结果。。。囧,楼主再测一测吧,看看有没有没有照顾到的情况