☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺ • 1年前
#include <bits/stdc++.h> using namespace std;
int main() {
int a[200][200];
int n;
cin >> n;
memset(a, 0, sizeof(a));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (i == 1 || i == n) {
for (int k = 1; k <= n; k++) {
a[i][k] = 1;
}
break;
}
if (j == 1 || j == n) {
a[i][j] = 1;
}
}
}
int p = n / 2, q = p + 1;
int flag = 0;
for (int i = 2; i <= n; i++) {
if (p == 2 && q == n - 2 + 1) {
a[i][p] = 1;
a[i][q] = 1;
break;
}
a[i][q] = 1;
a[i][p] = 1;
p--;
q++;
}
p = 2, q = n - 1;
for (int i = n / 2 + 1; i <= n; i++) {
a[i][p] = 1;
a[i][q] = 1;
p++;
q--;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (a[i][j] == 1) {
cout << "*";
} else {
cout << " ";
}
}
cout << endl;
}
return 0;
}
评论:
请先登录,才能进行评论