#include <iostream>
#include <Windows.h>
#define MAX 1001
using namespace std;
int main()
{
long t1 = GetTickCount64();
char a[MAX][MAX];
int n, m, i, j;
cin >> n;
m = 5 + 4 * n;
int sx = 1, sy = 1;
int ex = m, ey = m;
for (i = 1; i <= m; ++i)
for (j = 1; j <= m; ++j)
a[i][j] = '.';
while (n--) //由外层到内层一层一层画出来
{
sx += 2;
ex -= 2;
for (i = sx; i <= ex; ++i)
{
a[sy][i] = '$';
a[ey][i] = '$';
}
sy += 2;
ey -= 2;
for (i = sy; i <= ey; ++i)
{
a[i][sx - 2] = '$';
a[i][ex + 2] = '$';
}
a[sx][sy] = a[sx][ey] = a[ex][sy] = a[ex][ey] = '$';
a[sy - 1][sx] = a[sy - 1][ex] = '$';
a[sy][sx - 1] = a[sy][ex + 1] = '$';
a[ey][sx - 1] = a[ey][ex + 1] = '$';
a[ey + 1][sx] = a[ey + 1][ex] = '$';
}
for (i = sy; i <= ey; ++i)
a[i][sx + 2] = '$';
for (i = sx; i <= ex; ++i)
a[sy + 2][i] = '$';
for (i = 1; i <= m; ++i)
{
for (j = 1; j <= m; ++j)
cout << a[i][j];
cout << endl;
}
long t2 = GetTickCount64(); //结束时间
cout << "程序执行时间:" << t2 - t1 << "毫秒" << endl; //程序运行的时间得到的时间单位为毫秒 /1000为秒
}
题目 1442: [蓝桥杯][2013年第四届真题]打印十字图
最新推荐文章于 2024-11-15 21:44:47 发布