题解 | #蛇形矩阵#

蛇形矩阵

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

#include <iostream>
#include <vector>
using namespace std;

int main() {
    int count = 0;
    int num = 1;
    int x;
    while (cin >> count) { // 注意 while 处理多个 case
    vector<vector<int>> store(count);
        for(int i = 0;i<count;i++){{
            int tem = i;
            for(int j = 0;j<count&&tem>=0;j++){
                    store[tem].push_back(num);
                    num++;
                    tem--;
                }
            }
        }
        for(int i = 0;i<store.size();i++){
            for(int j = 0;j<store[i].size();j++){
                if(j == store[i].size()-1){
                    cout<<store[i][j]<<endl;
                }else{
                    cout<<store[i][j]<<' ';
                }
            }
        }
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

点赞 评论 收藏
分享
是每个人事都这样与找工作的人这样沟通吗?正常询问不可以吗
据说名字越长别人越关注你的昵称我觉得我要被关注了:excal 我还真不会
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
06-25 17:22
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务