题解 | #蛇形矩阵#

蛇形矩阵

https://www.nowcoder.com/practice/649b210ef44446e3b1cd1be6fa4cab5e

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

int main() {
    int n;
    cin >> n;
    vector<vector<int>> a(n, vector<int>(n,0));
    a[0][0] = 1;
    int m;
    for(int i=0; i<n; i++){
        m=n-i;
        if(i!=0) a[i][0] = a[i-1][0] + i;
        for(int j=0; j<m; j++){
            if(j!=0)a[i][j] = a[i][j-1] + j + 1 + i;
            cout << a[i][j] << " ";
        }
        cout << endl;
    }
    
    return 0;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

学不完不睡觉11:一眼点评,不过,看运气吧
点赞 评论 收藏
分享
虚闻松声:继续投吧。 简历没啥问题。很优秀。 拙见:自我评价没什么意义;试试转向Agent开发、大模型应用;别死磕传统Java开发。 免费修改简历,就业咨询,欢迎私信交流。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务