解题思路: 取1/4块图形来做区域填数,然后输出的时候再做对称输出就可以了QWQ。
注意事项: 0是个十字,没任何框框的
参考代码:
#include <stdio.h> int main(){ int map[125][125] = {0}; int n; int i,j,k; int r,c; scanf("%d", &n); r = c = (4*n+5)/2+1; //取1/4块图形的大小 //初始化 map[r][c] = 1; map[r][c-1] = 1; map[r][c-2] = 1; map[r-1][c] = 1; map[r-2][c] = 1; map[r][c-3] = -1; map[r-1][c-3] = -1; map[r-1][c-2] = -1; map[r-1][c-1] = -1; map[r-2][c-1] = -1; map[r-3][c-1] = -1; map[r-3][c] = -1; for(i = 1; i <= n; i++){ //枚举每个区域块 //设置不可填位置 map[r-(4*i+5)/2][r-(4*i+5)/2] = -1; map[r-(4*i+5)/2+1][r-(4*i+5)/2] = -1; map[r-(4*i+5)/2+1][r-(4*i+5)/2+1] = -1; map[r-(4*i+5)/2][r-(4*i+5)/2+1] = -1; //对当前区域块进行填数 for(j = (r-(4*i+5)/2); j <= r; j++){ for(k = (r-(4*i+5)/2); k <= c; k++){ if(map[j][k] != -1) map[j][k] = 1; } } //设置不可填位置 for(j = (r-(4*i+5)/2); j <= r; j++){ for(k = (r-(4*i+5)/2); k <= c; k++){ if(map[j][k] == 1){ if(map[j-1][k] == 0) //上 map[j-1][k] = -1; if(map[j+1][k] == 0) //下 map[j+1][k] = -1; if(map[j][k-1] == 0) //左 map[j][k-1] = -1; if(map[j][k+1] == 0) //右 map[j][k+1] = -1; if(map[j-1][k-1] == 0) //左上 map[j-1][k-1] = -1; if(map[j+1][k-1] == 0) //左下 map[j+1][k-1] = -1; if(map[j-1][k+1] == 0) //右上 map[j-1][k+1] = -1; if(map[j+1][k+1] == 0) //右下 map[j+1][k+1] = -1; } } } //让不可填位置可填 map[r-(4*i+5)/2][r-(4*i+5)/2] = 0; } //对称输出 for(j = 1; j <= r; j++){ for(k = 1; k <= c; k++){ if(map[j][k] == 1) printf("$"); else printf("."); } for(k = c-1; k >= 1; k--){ if(map[j][k] == 1) printf("$"); else printf("."); } printf("\n"); } for(j = r-1; j >= 1; j--){ for(k = 1; k <= c; k++){ if(map[j][k] == 1) printf("$"); else printf("."); } for(k = c-1; k >= 1; k--){ if(map[j][k] == 1) printf("$"); else printf("."); } printf("\n"); } return 0; }
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题9.2 (C语言代码)浏览:741 |
C语言训练-立方和不等式 (C语言代码)浏览:779 |
C语言程序设计教程(第三版)课后习题6.3 (C语言代码)浏览:553 |
不会做的浏览:954 |
C语言程序设计教程(第三版)课后习题7.2 (C语言代码)浏览:686 |
校门外的树 (C语言代码)浏览:733 |
三角形 (C语言代码)浏览:965 |
蛇行矩阵 (C语言代码)浏览:606 |
IP判断 (C语言描述,蓝桥杯)浏览:1118 |
1157题解浏览:769 |