文章

85

粉丝

0

获赞

568

访问

12.6k

头像
旋转方阵 题解:

#include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin >> n;

    int mat[20][20] = {0};

    int top = 0, bottom = n - 1, left = 0, right = n - 1;
    int num = 1;

    while (num <= n * n) {
        for (int i = top; i <= bottom; i++) mat[i][left] = num++;
        left++;
        for (int j = left; j <= right; j++) mat[bottom][j] = num++;
        bottom--;
        for (int i = bottom; i >= top; i--) mat[i][right] = num++;
        right--;
        for (int j = right; j >= left; j--) mat[top][j] = num++;
        top++;
    }

    int maxNum = n * n;
    int width = 0;
    while (maxNum) {
        width++;
       ...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发