| Run ID | 作者 | 问题 | 语言 | 测评结果 | 时间 | 内存 | 代码长度 | 提交时间 |
|---|---|---|---|---|---|---|---|---|
| 91860 | sh25_shenpy | 回形取数 | C++ | 解答错误 | 0 MS | 264 KB | 1402 | 2026-06-17 19:58:19 |
#include <iostream> #include <vector> using namespace std; int main() { // 优化IO ios::sync_with_stdio(false); cin.tie(NULL); int m, n; if (!(cin >> m >> n)) return 0; vector<vector<int>> matrix(m, vector<int>(n)); for (int i = 0; i < m; ++i) { for (int j = 0; j < n; ++j) { cin >> matrix[i][j]; } } int top = 0, bottom = m - 1; int left = 0, right = n - 1; bool first = true; // 用于控制空格输出 while (top <= bottom && left <= right) { for (int i = top; i <= bottom; ++i) { if (!first) cout << " "; cout << matrix[i][left]; first = false; } left++; if (left <= right) { // 检查边界有效性 for (int j = left; j <= right; ++j) { cout << " " << matrix[bottom][j]; } bottom--; } if (top <= bottom) { // 检查边界有效性 for (int i = bottom; i >= top; --i) { cout << " " << matrix[i][right]; } right--; } if (left <= right) { // 检查边界有效性 for (int j = right; j >= left; --j) { cout << " " << matrix[top][j]; } top++; } } cout << endl; return 0; }