拼多多笔试第一题

太难了,唯一Ac100%的题

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            int n= in.nextInt();
            int[][] arr=new int[n][n];
            solution(n,arr);
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < n; j++){
                    System.out.print(arr[i][j]+" ");
                }
                System.out.println();
            }
        }
    }

    private static void solution(int n, int[][] arr) {
        if (n%2==0){
            int left=0;
            int right =n-1;
            int top= 0;
            int bottom=n-1;
            int t=n-1;
            while (left<=right&&top <=bottom){
                for (int i=right;i>=left; i--){
                    if (i==right||i==left){
                        arr[top][i]=0;
                        continue;
                    }
                    if (i>(t)/2){
                        arr[top][i]=1;
                    }else {
                        arr[top][i]=2;
                    }
                }
                top++;
                for (int i=top;i<=bottom; i++){
                    if (i==bottom){
                        arr[i][left]=0;
                        continue;
                    }
                    if (i>(t)/2){
                        arr[i][left]=4;
                    }else {
                        arr[i][left]=3;
                    }
                }
                left++;
                for (int i=left;i<=right; i++){
                    if (i==right){
                        arr[bottom][i]=0;
                        continue;
                    }
                    if (i>(t)/2){
                        arr[bottom][i]=6;
                    }else {
                        arr[bottom][i]=5;
                    }
                }
                bottom--;
                for (int i=bottom;i>=top; i--){
                    if (i>(t)/2){
                        arr[i][right]=7;
                    }else {
                        arr[i][right]=8;
                    }
                }
                right--;
            }
        }else {
            int left=0;
            int right =n-1;
            int top= 0;
            int bottom=n-1;
            int t=n-1;
            while (left<=right&&top <=bottom){
                for (int i=right;i>=left; i--){
                    if (i==right||i==left||i==t/2){
                        arr[top][i]=0;
                        continue;
                    }
                    if (i>(t)/2){
                        arr[top][i]=1;
                    }else {
                        arr[top][i]=2;
                    }
                }
                top++;
                for (int i=top;i<=bottom; i++){
                    if (i==bottom||i==t/2){
                        arr[i][left]=0;
                        continue;
                    }
                    if (i>(t)/2){
                        arr[i][left]=4;
                    }else {
                        arr[i][left]=3;
                    }
                }
                left++;
                for (int i=left;i<=right; i++){
                    if (i==right||i==t/2){
                        arr[bottom][i]=0;
                        continue;
                    }
                    if (i>(t)/2){
                        arr[bottom][i]=6;
                    }else {
                        arr[bottom][i]=5;
                    }
                }
                bottom--;
                for (int i=bottom;i>=top; i--){
                    if (i==t/2){
                        arr[i][right]=0;
                        continue;
                    }
                    if (i>(t)/2){
                        arr[i][right]=7;
                    }else {
                        arr[i][right]=8;
                    }
                }
                right--;
            }
        }

    }
}
#笔试题目##拼多多#
全部评论
我也只会一个
点赞 回复 分享
发布于 2020-09-01 21:19
老哥。太暴力了
点赞 回复 分享
发布于 2020-09-01 21:15

相关推荐

07-05 16:23
门头沟学院 Java
mengnankk:我投了300,约了5 6个面试。感觉项目写的太多了。一个项目就写五六个亮点,不是把整个项目的功能描述下。其他的没啥,简历看起来有点长
点赞 评论 收藏
分享
Twilight_m...:表格简历有点难绷。说说个人看法: 1.个人基本情况里好多无意义信息,什么婚姻状况、健康状况、兴趣爱好、户口所在地、身份证号码、邮政编码,不知道的以为你填什么申请表呢。 2.校内实践个人认为对找工作几乎没帮助,建议换成和测开有关的项目,实在没得写留着也行。 3.工作经历完全看不出来是干什么的,起码看着和计算机没啥关系,建议加强描述,写点你在工作期间的实际产出、解决了什么问题。 4.个人简述大而空,看着像AI生成,感觉问题最大。“Python,C,C++成为我打造高效稳定服务的得力工具”、“我渴望凭借自身技术知识与创新能力,推动人工智能技术的应用发展,助力社会实现智能化转型”有种小学作文的美感。而且你确定你个人简述里写的你都会嘛?你AI这块写的什么“深入研究”,发几篇顶会的硕博生都不一定敢这么写。而且你AI这块的能力和软测也完全无关啊。个人简述建议写你对哪些技术栈、哪些语言、哪些生产工具的掌握,写的有条理些,而且最好是和测开强相关的。
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

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