第二题 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-15 13:12
已编辑
门头沟学院 Java
斯卡蒂味的鱼汤:知道你不会来数马,就不捞你😂最近数马疯狂扩招,招聘要求挺低的,你能力肯定够,应该就是因为太强了,知道你不会来才不捞你
投递腾讯云智研发等公司10个岗位
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务