题解 | #图片整理#

蛇形矩阵

http://www.nowcoder.com/practice/649b210ef44446e3b1cd1be6fa4cab5e

/*
1 3 6 10            1
2 5 9               2 3
4 8        ------>> 4 5 6  
7                   7 8 9 10

*/


import java.util.*;

public class Main{
    public static int[][] arrs = new int[100][100];
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int temp = 0;
        for(int i = 1; i <= a; i++){
            for(int j = 1; j <= i; j++){
                arrs[i][j] = ++temp;
            }
        }
        int flag = 0;
        for(int j = 1; j <= a; j++){
            flag = 1;
            for(int i = 0; i <= a - j ; i++){
                 System.out.print(arrs[j + i][i + 1] + " ");
            }
            System.out.println();
        }
        
     }
}
全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务