题解 | #蛇形矩阵#

蛇形矩阵

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

import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            int n = sc.nextInt();
            int[][] result = new int[n][];
            int t = 1;
            for(int i = 0;i<n;i++){
                result[i] = new int[n-i];
                for(int j=0;j<i+1;j++){
                    result[i-j][j] = t;
                    t++;
                }
            }
            for(int[] a:result){
                for(int a1 : a){
                    System.out.print(a1+" ");
                }
                System.out.println();
            }
        }
    }
}
全部评论

相关推荐

哈哈哈,你是老六:百度去年裁员分评不好,赶紧弄点红包
点赞 评论 收藏
分享
评论
1
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务