题解 | #蛇形矩阵#
蛇形矩阵
http://www.nowcoder.com/practice/649b210ef44446e3b1cd1be6fa4cab5e
//简洁明了,
import java.util.*;
import java.io.*;
public class Main{
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String s=null;
while((s=br.readLine())!=null){
int n=Integer.valueOf(s);
int sum=0;
int ss=0;
int first=1;
for(int i=1;i<n+1;i++){
for(int j=0;j<=n-i;j++){
if(j==0)
sum=first;
else
sum=sum+i+j;
System.out.print(sum+" ");
}
System.out.println();
first=first+i;
}
}
}
}