# 字母旋转方阵

A B C D E F G H

V W X Y Z A B I

U J K L M N C J

T I H G F E D K

S R Q P O N M L

M为行数，N为列数，其中M，N都为大于0的整数。

``4 9``

`````` A B C D E F G H I
V W X Y Z A B C J
U J I H G F E D K
T S R Q P O N M L``````

``````#include <stdio.h>
int main()
{
int m, n;
int flag = 0;
int num1 = 0, num2 = 1;
int i = 0, j = 0;
char s = 'A';
char a[31][31];
scanf("%d %d",&m,&n);
a[0][0] = s;
while(flag < m*n-1)
{
switch(num2%4)
{
case 1:
++j;
if(j == n-num1-1)
{
num2++;
}
break;
case 2:
++i;
if(i == m-num1-1)
{
num2++;
}
break;
case 3:
--j;
if(j == num1)
{
num2++;
}
break;
case 0:
--i;
if(i == num1+1)
{
num2++;
num1++;
}
break;
}
if(++s == 'Z'+1)
s = 'A';
a[i][j]=s;
flag++;
}
for(i=0; i<m; i++)
{
printf(" ");
for(j=0; j<n; j++)
{
if(j!=n-1)
printf("%c ", a[i][j]);
else
printf("%c", a[i][j]);
}
printf("\n");

}

}
``````

``````#include <stdio.h>
int main()
{
int m, n;
int flag = 0;
int num1 = 0, num2 = 1;
int i = 0, j = 0;
char s = 'A';
char a[31][31];
scanf("%d %d",&m,&n);
a[0][0] = s;
while(flag < m*n-1)
{
switch(num2%4)
{
case 1:
++j;
if(j == n-num1-1)
{
num2++;
}
break;
case 2:
++i;
if(i == m-num1-1)
{
num2++;
}
break;
case 3:
--j;
if(j == num1)
{
num2++;
}
break;
case 0:
--i;
if(i == num1+1)
{
num2++;
num1++;
}
break;
}
if(++s == 'Z'+1)
s = 'A';
a[i][j]=s;
flag++;
}
for(i=0; i<m; i++)
{
printf(" ");
for(j=0; j<n; j++)
{
if(j!=n-1)
printf("%c ", a[i][j]);
else
printf("%c", a[i][j]);
}
printf("\n");

}

}
``````