我的代码??
#include <iostream>
#include <stdio.h>
using namespace std;
void print(int n) {
cout << "..";
for (int i = 0; i < n * 4 + 1; ++i)
cout << "$";
cout << ".." << endl << "..$";
for (int i = 0; i < n * 4 - 1; ++i)
cout << ".";
cout << "$.." << endl;
//前两行
for (int i = 1; i <= 2 * n + 1; ++i) {
if (i % 2) { //奇数行
for (int j = 0; j < (i - 1) / 2; ++j)
cout << "$.";
if (i != 2 * n + 1) {
cout << "$$$.";
for (int j = 0; j < (n + 1) * 4 + 1 - (i - 1) * 2 - 8; ++j)
cout << "$";
cout << ".$$$";
} else //中间行
for (int j = 0; j < (n + 1) * 4 + 1 - (i - 1) * 2; ++j)
cout << "$";
for (int j = 0; j < (i - 1) / 2; ++j)
cout << ".$";
cout << endl;
} else { //偶数行
cout << "$";
for (int j = 0; j < (i - 1) / 2; ++j)
cout << ".$";
cout << "...$";
for (int j = 0; j < (n + 1) * 4 + 1 - 2 - (i - 1) / 2 * 4 - 8; ++j)
cout << ".";
if (i != 2 * n)
cout << "$...";
else cout << "...";
for (int j = 0; j < (i - 1) / 2; ++j)
cout << "$.";
cout << "$" << endl;
}
}
//后半部分
for (int i = 2 * n; i > 0; --i) {
if (i % 2) { //奇数行
for (int j = 0; j < (i - 1) / 2; ++j)
cout << "$.";
if (i != 2 * n + 1) {
cout << "$$$.";
for (int j = 0; j < (n + 1) * 4 + 1 - (i - 1) * 2 - 8; ++j)
cout << "$";
cout << ".$$$";
} else //中间行
for (int j = 0; j < (n + 1) * 4 + 1 - (i - 1) * 2; ++j)
cout << "$";
for (int j = 0; j < (i - 1) / 2; ++j)
cout << ".$";
cout << endl;
} else { //偶数行
cout << "$";
for (int j = 0; j < (i - 1) / 2; ++j)
cout << ".$";
cout << "...$";
for (int j = 0; j < (n + 1) * 4 + 1 - 2 - (i - 1) / 2 * 4 - 8; ++j)
cout << ".";
if (i != 2 * n)
cout << "$...";
else cout << "...";
for (int j = 0; j < (i - 1) / 2; ++j)
cout << "$.";
cout << "$" << endl;
}
}
cout << "..$";
for (int i = 0; i < n * 4 - 1; ++i)
cout << ".";
cout << "$.." << endl << "..";
for (int i = 0; i < n * 4 + 1; ++i)
cout << "$";
cout << "..";
//后两行
}
int main() {
int n;
cin >> n;
print(n);
return 0;
}
|