解题思路:
题干已经提示很明显了,一笔一笔写是最方便的
注意事项:
参考代码:
#include <iostream> #include <vector> #include <map> #include <algorithm> #include <stdio.h> #define N 50 using namespace std; char G[2*N-1][2*N-1]; void initG (int n) { for (int i = 0; i < 2*n - 1; i++) for (int j = 0; j < 2*n - 1; j++) G[i][j] = '.'; } void printGraph (int n) { initG(n); for (int i = 0; i <= n - 1; i++) { G[n-1][i] = G[n-1][2*n-2-i] = 'A' + i; G[i][n-1] = G[2*n-2-i][n-1] = 'A' + i; G[i][i] = G[2*n-2-i][2*n-2-i] = G[i][2*n-2-i] = G[2*n-2-i][i] = 'A' + i; } for (int i = 0; i < 2*n - 1; i++) { for (int j = 0; j < 2*n - 1; j++) cout << G[i][j]; cout << endl; } } int main(void) { int n = 0; cin >> n; printGraph(n); return 0; } 【思路二】 #include <iostream> #include <cstring> #include <algorithm> using namespace std; const int maxn = 100; int n; char str[maxn][maxn]; char Num[26] = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'}; int main(void){ cin >> n; int tmp = 2*n-1; /*初始化*/ for(int i = 0; i <= tmp; i++){ memset(str[i], '.', sizeof(str[i])); } for(int i = 0; i < n-1; i++){ str[i][i] = str[tmp-i-1][tmp-i-1] = Num[i]; str[i][n-1] = str[tmp-i-1][n-1] = Num[i]; str[i][tmp-i-1] = str[tmp-i-1][i] = Num[i]; } for(int i = 0; i < n; i++){ str[n-1][i] = str[n-1][tmp-i-1] = Num[i]; } for(int i = 0; i < tmp; i++){ for(int j = 0; j < tmp; j++){ cout << str[i][j]; } cout << endl; } return 0; }
0.0分
1 人评分
C语言程序设计教程(第三版)课后习题7.1 (C++代码)浏览:726 |
Minesweeper (C语言代码)浏览:860 |
倒杨辉三角形 (C语言代码)浏览:4047 |
C语言程序设计教程(第三版)课后习题8.8 (C语言代码)浏览:717 |
C语言程序设计教程(第三版)课后习题6.4 (C语言代码)浏览:559 |
简单的a+b (C语言代码)浏览:828 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:1334 |
C语言程序设计教程(第三版)课后习题6.5 (C++代码)浏览:487 |
K-进制数 (C语言描述,蓝桥杯)浏览:956 |
【亲和数】 (C语言代码)浏览:628 |