题解 | #蛇形矩阵#
蛇形矩阵
https://www.nowcoder.com/practice/649b210ef44446e3b1cd1be6fa4cab5e
#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char* argv[]){
int N;
cin >> N;
int startNum = 1;
for(int i = 0; i < N; ++i){
startNum += i;
cout << startNum << " ";
int startPlus = i + 2;
for(int j = 1; j < N - i; ++j){
cout << startNum + startPlus << " ";
startPlus += i + j + 2 ;
}
cout << endl;
}
return 0;
}