本帖最后由 jackz007 于 2020-12-27 22:05 编辑 #include <stdio.h>
char fun(int i , int j , int n)
{
char c ;
int k , p , x , y ;
p = n * 2 - 1 ;
if(i >= 0 && i <= p - 1 && j >= 0 && j <= p - 1) {
x = (i > n - 1) ? 2 * n - 2 - i : i ;
y = (j > n - 1) ? 2 * n - 2 - j : j ;
c = '.' ;
if(x == n - 1) {
c = y + 'A' ;
} else {
if(x == y || y == n - 1) c = x + 'A' ;
}
}
return c ;
}
main(void)
{
int i ,j , k , m ;
scanf("%d" , & m) ;
for(i = 0 ; i < m * 2 - 1 ; i ++) {
for(j = 0 ; j < m * 2 - 1 ; j ++) {
printf("%c" , fun(i , j , m)) ;
}
printf("\n") ;
}
}
编译、运行实况D:\00.Excise\C>g++ -o x x.c
D:\00.Excise\C>x
4
A..A..A
.B.B.B.
..CCC..
ABCDCBA
..CCC..
.B.B.B.
A..A..A
D:\00.Excise\C>x
5
A...A...A
.B..B..B.
..C.C.C..
...DDD...
ABCDEDCBA
...DDD...
..C.C.C..
.B..B..B.
A...A...A
D:\00.Excise\C>x
8
A......A......A
.B.....B.....B.
..C....C....C..
...D...D...D...
....E..E..E....
.....F.F.F.....
......GGG......
ABCDEFGHGFEDCBA
......GGG......
.....F.F.F.....
....E..E..E....
...D...D...D...
..C....C....C..
.B.....B.....B.
A......A......A
D:\00.Excise\C>
|