Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
139478 | 黄子轩 | 蛇形矩阵2 | C++ | 编译错误 | 0 | 0 MS | 0 KB | 584 | 2024-03-23 17:27:50 |
include <bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; int a[n + 1][n + 1]; int t = 1; memset(a, 0, sizeof(a)); for(int i = n * 2 + 1; i >= 1; i--){ int y = i, x = 1; while(y >= 1){ if(x <= n && y <= n){ if(i % 2 != 0){ a[x][y] = t++; } else{ a[y][x] = t++; } } y--; x++; } } for(int i = 1; i <= n / 2; i++){ for(int j = 1; j <= n; j++){ swap(a[i][j], a[n - i + 1][j]); } } for(int i = 1; i <= n; i++){ for(int j = 1; j <= n; j++){ cout << setw(5) << a[i][j]; } cout << endl; } return 0; }