import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args){ Scanner in = new Scanner(System.in); int N = in.nextInt(); int[][] Ser = new int[N][N]; int num = 1;//数字 int count = 0;//蛇形数字斜行个数 int h = 0;//行 int l = 0;//列 for (int i = 0; i < N; i++) { count = 0; for (int j = 0; j < N; j++) { Ser[h][l] = num; num++; if(count == i){ h=i+1; l=0; break; }else { h--; l++; count++; } } } int hcount = N-1;//每行的数字个数 for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if(Ser[i][j]!= 0 && j < hcount){ System.out.print(Ser[i][j]+" "); }else if(Ser[i][j]!= 0 && j == hcount){ System.out.println(Ser[i][j]); hcount--; } } } } }