小明为某机构设计了一个十字型的徽标(并非红十字会啊),如下所示:
..$$$$$$$$$$$$$..
..$...........$..
$$$.$$$$$$$$$.$$$
$...$.......$...$
$.$$$.$$$$$.$$$.$
$.$...$...$...$.$
$.$.$$$.$.$$$.$.$
$.$.$...$...$.$.$
$.$.$.$$$$$.$.$.$
$.$.$...$...$.$.$
$.$.$$$.$.$$$.$.$
$.$...$...$...$.$
$.$$$.$$$$$.$$$.$
$...$.......$...$
$$$.$$$$$$$$$.$$$
..$...........$..
..$$$$$$$$$$$$$..
对方同时也需要在电脑dos窗口中以字符的形式输出该标志,并能任意控制层数。
输入格式
一个正整数 n (n<30) 表示要求打印图形的层数。
输出格式
对应包围层数的该标志。
样例输入1
1
样例输出1
..$$$$$..
..$...$..
$$$.$.$$$
$...$...$
$.$$$$$.$
$...$...$
$$$.$.$$$
..$...$..
..$$$$$..
样例输入2
3
样例输出2
..$$$$$$$$$$$$$..
..$...........$..
$$$.$$$$$$$$$.$$$
$...$.......$...$
$.$$$.$$$$$.$$$.$
$.$...$...$...$.$
$.$.$$$.$.$$$.$.$
$.$.$...$...$.$.$
$.$.$.$$$$$.$.$.$
$.$.$...$...$.$.$
$.$.$$$.$.$$$.$.$
$.$...$...$...$.$
$.$$$.$$$$$.$$$.$
$...$.......$...$
$$$.$$$$$$$$$.$$$
..$...........$..
..$$$$$$$$$$$$$..
请仔细观察样例,尤其要注意句点的数量和输出位置。
是时候祭出这张图了,再次原谅我拙劣的画图技能……
#include <iostream>
#include <vector>
using namespace std;
void printVector2(vector<vector<char> > res) {
for (int i = 0; i < res.size(); i++) {
for (int j = 0; j < res.size(); j++)
cout << res[i][j];
cout << endl;
}
}
void changeAtRow(int start, int end, int row, vector<vector<char> > &res) {
for (int col = start; col <= end; col++)
res[row][col] = '$';
}
void changeAtCol(int start, int end, int col, vector<vector<char> > &res) {
for (int row = start; row <= end; row++)
res[row][col] = '$';
}
void printFlag(int n) {
int length = 1 + 4 * n + 2 * 2;
vector<vector<char> > res(length, vector<char>(length, '.'));
for (int i = n; i >= 0; i--) {
int start = 2 * (n - i) + 2;
int end = start + 1 + i * 4 - 1;
int row = 2 * (n - i);
int row2 = row + i * 4 + 4;
changeAtRow(start, end, row, res);
changeAtRow(start, end, row2, res);
changeAtCol(row, row + 2, start, res);
changeAtCol(row, row + 2, end, res);
changeAtCol(row2 - 2, row2, start, res);
changeAtCol(row2 - 2, row2, end, res);
}
for (int i = n; i >= 0; i--) {
int start = 2 * (n - i) + 2;
int end = start + 1 + i * 4 - 1;
int col = 2 * (n - i);
int col2 = col + i * 4 + 4;
changeAtCol(start, end, col, res);
changeAtCol(start, end, col + i * 4 + 4, res);
changeAtRow(col, col + 2, start, res);
changeAtRow(col, col + 2, end, res);
changeAtRow(col2 - 2, col2, start, res);
changeAtRow(col2 - 2, col2, end, res);
}
printVector2(res);
}
int main(int argc, char *argv[]) {
int n;
cin >> n;
printFlag(n);
return 0;
}