WeBank笔试

WeBank笔试题目讨论

第一题

没啥好说的应该都过

第二题

第二题我只过了82%不知道为什么,我觉得自己都考虑到了,希望有大神能帮忙解答一下

题目描述:
旋转数组并输出
x为顺时针,y水平反转,z逆时针
package cn.webank;

import java.util.Arrays;
import java.util.Scanner;

public class Demo02 {
    static int m,n;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int x = scanner.nextInt()%4;
        int y = scanner.nextInt()%2;
        int z = scanner.nextInt()%4;

        n = scanner.nextInt();
        m = scanner.nextInt();

        int Q = scanner.nextInt();

        Point[] res=new Point[Q];

        for (int i = 0; i < Q; i++) {
            int x1 = scanner.nextInt();
            int y1 = scanner.nextInt();

            Point p=new Point(x1,y1);
            for (int j = 0; j < x; j++) {
                p=rotateX(p.x,p.y);
                int temp=m;
                m=n;
                n=temp;
            }

            for (int j = 0; j < y; j++) {
                p=rotateY(p.x,p.y);
            }

            for (int j = 0; j < z; j++) {
                p=rotateZ(p.x,p.y);
                int temp=m;
                m=n;
                n=temp;
            }

            res[i]=p;

        }

        Arrays.stream(res).forEach(each-> System.out.println(each.x+" "+each.y));






    }
    public static Point rotateX(int x,int y){
        return new Point(y,n-x+1);
    }

    public static Point rotateZ(int x,int y){
        return new Point(m-y+1,x);
    }

    public static Point rotateY(int x,int y){
        return new Point(x,m-y+1);
    }


}

class Point{
    int x;
    int y;

    public Point(int x, int y) {
        this.x = x;
        this.y = y;
    }
}


第三题

第三题代码我只过了18%
package cn.webank;

import java.util.Scanner;

public class Demo03 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();

        int[] arr=new int[n];
        for (int i = 0; i < n; i++) {
            arr[i]=scanner.nextInt();
        }
        int[] res=new int[n];
        for (int i = 0; i < n; i++) {
            res[i]=numXiaoyu(arr,res,i);
        }
        long count=0;
        for (int i = 0; i < n; i++) {
            if (res[i]<2){
                continue;
            }
            if (res[i]==2){
                count++;
            }else {
                count+=res[i]*(res[i]-1)/2;
            }
        }
        System.out.println(count);

    }

    public static int numXiaoyu(int[] arr,int[] res,int index){
        if (index==0){
            return 0;
        }
        for (int i = index-1; i >= 0 ; i--) {
            if (arr[index]>=arr[i]){
                return res[i]+1;
            }
        }
        return 0;
    }
}

主要的想法是动态规划,记录比自己小的数字的数量,并根据数量进行统计,2能够贡献1,更大的数贡献x*(x-1)/2,但是结果只能跑通18%,好像还是6的特殊情况🤐求助呀求助


#笔试题型##微众银行#
全部评论

相关推荐

来个厂收我吧:首先,市场侧求职我不是很懂。 但是,如果hr把这份简历给我,我会觉得求职人不适合做产品经理。 问题点: 1,简历的字体格式不统一,排版不尽如人意 2,重点不突出,建议参考star法则写个人经历 3,印尼官方货币名称为印度尼西亚卢比(IDR),且GMV690000印尼盾换算为305人民币,总成交额不高。 4,右上角的意向职位在发给其他公司时记得删除。 5,你所有的经历都是新媒体运营,但是你要投市场营销岗位,jd和简历不匹配,建议用AI+提示词,参照多个jd改一下经历内容。 修改建议: 1,统一字体(中文:思源黑体或微软雅黑,英文数字:time new romans),在word中通过表格进行排版(b站学) 2,校招个人经历权重:实习经历=创业经历(大创另算)>项目经历>实训经历>校园经历 3,请将项目经历时间顺序改为倒序,最新的放最上方。 4,求职方向不同,简历文字描述侧重点也需要不同。
点赞 评论 收藏
分享
05-29 09:02
门头沟学院 Java
点赞 评论 收藏
分享
评论
1
2
分享

创作者周榜

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