打印十字图
时间限制: 1S类别: 循环结构->较难
问题描述 :
小明为某机构设计了一个十字型的徽标(并非红十字会啊),如下所示:
..$$$$$$$$$$$$$..
..$...........$..
$$$.$$$$$$$$$.$$$
$...$.......$...$
$.$$$.$$$$$.$$$.$
$.$...$...$...$.$
$.$.$$$.$.$$$.$.$
$.$.$...$...$.$.$
$.$.$.$$$$$.$.$.$
$.$.$...$...$.$.$
$.$.$$$.$.$$$.$.$
$.$...$...$...$.$
$.$$$.$$$$$.$$$.$
$...$.......$...$
$$$.$$$$$$$$$.$$$
..$...........$..
..$$$$$$$$$$$$$..
对方同时也需要在电脑dos窗口中以字符的形式输出该标志(图中红色只是为了标记处十字符号,输出时都用黑色),并能任意控十字外面包围的符号的层数。
输入说明 :
一个正整数 n (n<30) 表示要求打印图形的层数。
输出说明 :
对应包围层数的该标志。
比如:
输入
1
输出
..$$$$$..
..$...$..
$$$.$.$$$
$...$...$
$.$$$$$.$
$...$...$
$$$.$.$$$
..$...$..
..$$$$$..
输入
3
输出
..$$$$$$$$$$$$$..
..$...........$..
$$$.$$$$$$$$$.$$$
$...$.......$...$
$.$$$.$$$$$.$$$.$
$.$...$...$...$.$
$.$.$$$.$.$$$.$.$
$.$.$...$...$.$.$
$.$.$.$$$$$.$.$.$
$.$.$...$...$.$.$
$.$.$$$.$.$$$.$.$
$.$...$...$...$.$
$.$$$.$$$$$.$$$.$
$...$.......$...$
$$$.$$$$$$$$$.$$$
..$...........$..
..$$$$$$$$$$$$$..
请仔细观察样例,尤其要注意句点的数量和输出位置。
输入范例 :
3
输出范例 :
..$$$$$$$$$$$$$..
..$...........$..
$$$.$$$$$$$$$.$$$
$...$.......$...$
$.$$$.$$$$$.$$$.$
$.$...$...$...$.$
$.$.$$$.$.$$$.$.$
$.$.$...$...$.$.$
$.$.$.$$$$$.$.$.$
$.$.$...$...$.$.$
$.$.$$$.$.$$$.$.$
$.$...$...$...$.$
$.$$$.$$$$$.$$$.$
$...$.......$...$
$$$.$$$$$$$$$.$$$
..$...........$..
..$$$$$$$$$$$$$..
#include<iostream>
using namespace std;
const int maxnum = 130;
bool mmap[maxnum][maxnum];
void couttt(int n);
int main()
{
int m;
cin >> m;
//
couttt(m);
return 0;
}
void couttt(int n) {
int N = 5 + 4 * n;
for (int i = N / 2 - 1; i <= N / 2 + 3; i++)
mmap[N / 2 + 1][i] = mmap[i][N / 2 + 1] = true;
for (int i = 1; i <= n; i++)
{
int x = 2 * i + 1, y = 2 * i + 1;
mmap[x][y] = mmap[x][y - 1] = mmap[x - 1][y] = true;
y = N - 2 * i;
mmap[x][y] = mmap[x][y + 1] = mmap[x - 1][y] = true;
x = N - 2 * i;
mmap[x][y] = mmap[x][y + 1] = mmap[x + 1][y] = true;
y = 2 * i + 1;
mmap[x][y] = mmap[x][y - 1] = mmap[x + 1][y] = true;
for (int j = 2 * i + 1; j <= N - 2 * i; j++)
mmap[2 * i - 1][j] = mmap[j][N - 2 * (i - 1)] = mmap[N - 2 * (i - 1)][j] = mmap[j][2 * i - 1] = true;
}
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++)
if (mmap[i][j]) cout << "$";
else cout << ".";
cout << endl;
}
}