民生银行提前批 “民芯计划” 技术岗笔试算法题

一共有两道题,第二题题没读太懂,当输入1的时候要求输出非空字符串数量,忽略了非空,导致ac14。

第一题ac   100  学生成绩排序问题
class Student{
    //学生类
    public String name;
    public int chinese;
    public int math;
    public int english;
    public int total;
    public int rank;
    public Student(String name,int chinese,int math,int english){
        this.name = name;
        this.chinese = chinese;
        this.math = math;
        this.english = english;
        this.total = this.chinese+this.math+this.english;
    }
    //最终输出的结果
    @Override
    public String toString(){
        StringBuilder sb = new StringBuilder();
        sb.append("rank:").append(rank).append(" ").
                append("name:").append(name).append(" ").
                append("total:").append(total).append(" ").
                append("chinese:").append(chinese).append(" ").
                append("math:").append(math).append(" ").
                append("english:").append(english);
        return sb.toString();

    }
}

public class T1 {
    public static void main(String[] args) throws IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        String str;
        while((str = bf.readLine()) !=null){
            Student stu[] = new Student[Integer.valueOf(str)];
            String []data;
            String name;
            int chinese,math,english;
            //处理输入
            for(int i=0;i<stu.length;i++){
                data = bf.readLine().split(" ");
                name = data[0];
                chinese = Integer.valueOf(data[1]);
                math = Integer.valueOf(data[2]);
                english = Integer.valueOf(data[3]);
                stu[i] = new Student(name,chinese,math,english);
            }
            //排序处理 重写Comparator
            Arrays.sort(stu, new Comparator<Student>() {
                @Override
                public int compare(Student o1, Student o2) {
                    if(o1.total!=o2.total){//总分
                        return o2.total-o1.total;
                    }else if(o1.chinese!=o2.chinese){
                        return  o2.chinese-o1.chinese;
                    }else if(o1.math != o2.math){
                        return  o2.math-o1.math;
                    }else if(o1.english!=o2.english){
                        return  o2.english-o1.english;
                    }else {
                        return o1.name.compareTo(o2.name);
                    }
                }
            });
            Student pre = stu[0];
            int rank = 1;
            stu[0].rank = rank;
            rank++;
            // 重点排序
            for(int i=1;i<stu.length;i++){
                if(stu[i].total!=pre.total||stu[i].chinese!=pre.chinese||stu[i].math!=pre.math||stu[i].english!=pre.english){
                    stu[i].rank = rank;
                }else{
                    //前后两个相同分数
                    stu[i].rank = pre.rank;
                }
                pre = stu[i];
                rank++;
            }
            for(int i=0;i<stu.length;i++){
                System.out.println(stu[i]);
            }

        }
    }
}





第二题:
其实就是简单的if else判断
class Main {
    public static void main(String[] args) throws IOException {
        String str;
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));

        while((str=bf.readLine())!=null){
            if(str.equals("1")){
                int count = 0;
                while((str =  bf.readLine())!=null){
                    if(str.equals("") == false)//一定要判读是否为空
                    count++;
                }
                System.out.println(count);
            }else if(str.equals("Q")){
                System.out.println("Quit");
            }else {
                System.out.println("Wrong input,Please re-choose");
                System.out.println("Menu Function Test");
                System.out.println("1: Count Lines");
                System.out.println("Q: Quit");
            }
        }
    }
}





#民生银行民芯计划##民生银行##笔试题目#
全部评论
有没有收到面试通知的😂
点赞 回复
分享
发布于 2021-07-01 00:45
楼主这是实习岗位吗?我投的实习还没反应
点赞 回复
分享
发布于 2021-07-07 15:28
联想
校招火热招聘中
官网直投

相关推荐

点赞 评论 收藏
转发
3 18 评论
分享
牛客网
牛客企业服务