第二题 91% public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); if(n == 0){ System.out.println(0); }else{ int sum = n*n; long [] array = new long[sum]; array[0] = 1; array[1] = 1; for(int i = 2;i<array.length;i++){ array[i] = array[i-1]+array[i-2]; } int temp = array.length-1; long [][] arrays = new long[n][n]; int top = 0; int left = 0; int right = n-1; int low = n-1; while (top<=low || left<=right){ if (top<=low){ for(int i = left;i<=right;i++){ arrays[top][i] = array[temp]; temp--; } top++; } if(right>=left){ for(int i = top;i<=low;i++){ arrays[i][right] = array[temp]; temp--; } right--; } if (low>=top){ for(int i = right;i>=left;i--){ arrays[low][i] = array[temp]; temp--; } low--; } if (left<=right){ for(int i = low;i>=top;i--){ arrays[i][left] = array[temp]; temp--; } left++; } } int num = 0; for(int i = 0;i<arrays.length;i++){ for(int j = 0;j<arrays[0].length;j++){ System.out.print(arrays[i][j]+" "); num++; if(num%n == 0){ System.out.println(); } } } } }
点赞 评论

相关推荐

点赞 评论 收藏
分享
11-04 14:10
东南大学 Java
_可乐多加冰_:去市公司包卖卡的
点赞 评论 收藏
分享
牛客网
牛客企业服务