题解
2023-06-27 19:42:36
发布于:上海
101阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
int list[n][n];
int a = 1, b = 1;
int count = 1;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
list[i][j] = 0;
}
}
for (int i = 0; i < n; ++i) {
if (a) {
for (int j = 0; j < n; ++j) {
list[i][j] = b;
++b;
}
a = 0;
} else {
for (int j = n - 1; j >= 0; --j) {
list[i][j] = b;
++b;
}
a = 1;
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
printf("%d ", list[i][j]);
}
printf("\n");
}
return 0;
}
这里空空如也
有帮助,赞一个