题解 | #蛇形矩阵#
蛇形矩阵
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")