You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
498 B

#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int a[N][N];
int x = 20, w;
// 测试数据 6
int main() {
cin >> w;
//构建蛇形矩阵
for (int i = 1; i <= x * w; i++) {
int r, c;
r = (i - 1) / w;
c = (i - 1) % w;
a[r][c] = i;
}
//输出构建结果
for (int i = 0; i < x; i++) {
for (int j = 0; j < w; j++)
printf("%3d ", a[i][j]);
printf("\n");
}
return 0;
}