样例输入
11Xo
6*E
样例输出
代码
#include <cstdio> #define MAX 80 char buf[MAX][MAX]; void mySwap(int& a, int& b) { int temp = a; a = b; b = temp; } void drawLine(int x1, int y1, int x2, int y2, char ch) { if (x1 == x2) { // 画直线 if (y1 > y2) mySwap(y1, y2); for (int j = y1; j <= y2; ++j) { buf[x1][j] = ch; } } else { // 画竖线 if (x1 > x2) mySwap(x1, x2); for (int i = x1; i <= x2; ++i) { buf[i][y1] = ch; } } } void drawCircle(int si, int sj, int width, char ch) { drawLine(si, sj, si, sj + width - 1, ch); drawLine(si, sj + width - 1, si + width - 1, sj + width - 1, ch); drawLine(si, sj, si + width - 1, sj, ch); drawLine(si + width - 1, sj, si + width - 1, si + width - 1, ch); } int main() { int width; char a, b; while (scanf("%d", &width) != EOF) { scanf("%c%c", &b, &a); int x = 0, y = 0, cur = a; int tmpWidth = width; while (tmpWidth > 0) { drawCircle(x++, y++, tmpWidth, cur); tmpWidth -= 2; cur = (cur == a ? b : a); } buf[0][0] = buf[width - 1][width - 1] = buf[0][width - 1] = buf[width - 1][0] = ' '; for (int i = 0; i <= width - 1; ++i) { for (int j = 0; j <= width - 1; ++j) { printf("%c", buf[i][j]); } printf(" "); } } return 0; }