题解 | #蛇形矩阵#
蛇形矩阵
https://www.nowcoder.com/practice/649b210ef44446e3b1cd1be6fa4cab5e
#include <iostream> #include <iterator> using namespace std; int main() { int n,k=1,temp=2,c=1,m=1; while (cin >> n) { // 注意 while 处理多个 case for(int i=1;i<=n;i++){ c++; temp=i+1; for(int j=1;j<=n-i+1;j++){ cout<<k<<" "; k=k+temp; temp++; } cout<<endl; c=i; m=m+c; k=m; } } }