题解 | #蛇形矩阵#
蛇形矩阵
https://www.nowcoder.com/practice/649b210ef44446e3b1cd1be6fa4cab5e
#include <iostream> #include <vector> using namespace std; int main() { int row; cin>>row; vector<vector<int>> res(row,vector<int>(row,0)); int x = 2; res[0][0] = 1; cout<<res[0][0]<<' '; for(int i = 1;i<row;i++){ res[0][i] = res[0][i-1]+x; x++; cout<<res[0][i]<<' '; } cout<<endl; for(int i = 1;i<row;i++){ x = i; for(int j = 0;j<row-i;j++){ res[i][j] = res[i-1][j]+x; x++; cout<<res[i][j]<<' '; } cout<<endl; } // for(int i = 0;i<row;i++){ // for(int j = 0;j<row-i;j++){ // cout<<res[i][j]; // } // } } // 64 位输出请用 printf("%lld")
记录