米哈游居然两个都a了,太难得了

其实写的挺乱的😂

第二题 就是类似与消消乐的一道题
import java.util.Scanner;

public class Main{
    private static int rows, cols;

    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        String[] firstLine = scanner.nextLine().split(" ");
        rows = Integer.parseInt(firstLine[0]);
        cols = Integer.parseInt(firstLine[1]);
        char[][] canvas = new char[rows][cols];
        for(int i = 0; i < rows; i++){
            String line = scanner.nextLine();
            for(int j = 0; j < cols; j++){
                canvas[i][j] = line.charAt(j);
            }
        }

        {
            String[] lastLine = scanner.nextLine().split(" ");
            int r1 = Integer.parseInt(lastLine[0]);
            int c1 = Integer.parseInt(lastLine[1]);
            int r2 = Integer.parseInt(lastLine[2]);
            int c2 = Integer.parseInt(lastLine[3]);

            char temp = canvas[r1][c1];
            canvas[r1][c1] = canvas[r2][c2];
            canvas[r2][c2] = temp;
        }


        scanner.close();

        int count = 0;
        while (true) {
            boolean[][] mark = new boolean[rows][cols];
            markRow(canvas, mark);
            markCol(canvas, mark);

            boolean flag = false;
            for (int i = 0; i < rows; i++) {
                for (int j = 0; j < cols; j++) {
                    if (mark[i][j]) {
                        count += 1;
                        canvas[i][j] = '0';
                        flag = true;
                    }
                }
            }

            if(!flag || !fallDown(canvas))
                break;
        }
        System.out.println(count);

    }

    private static boolean fallDown(char[][] canvas){
        boolean flag = false;
        for(int j = 0; j < cols; j++){
            int zero = -1;
            int alpha = -1;
            for(int i = rows - 1; i >= 0; i--){
                if(zero == -1 && canvas[i][j] == '0')
                    zero = i;
                if(alpha == -1 && canvas[i][j] != '0')
                    alpha = i;
            }

            if(zero == -1 || alpha == -1 || zero <= alpha)
                continue;

            flag = true;
            int dis = zero - alpha;
            for(int i = alpha; i >= 0; i--){
                canvas[i + dis][j] = canvas[i][j];
                canvas[i][j] = '0';
            }
        }
        return flag;
    }


    private static void markRow(char[][] canvas, boolean[][] mark){
        for(int i = 0; i < rows; i++) {
            char last = '!';
            int count = 0;
            for(int j = 0; j < cols; j++){
                char curr = canvas[i][j];
                if(curr == '0'){
                    count = 0;
                    continue;
                }
                if(curr == last){
                    count += 1;
                } else{
                    if(count >= 3){
                        markRow(i, j - 1, count, mark);
                    }
                    last = curr;
                    count = 1;
                }
            }
            if(count >= 3)
                markRow(i, cols - 1, count, mark);
        }
    }

    private static void markCol(char[][] canvas, boolean[][] mark){
        for(int j = 0; j < cols; j++) {
            char last = '!';
            int count = 0;
            for(int i = 0; i < rows; i++){
                char curr = canvas[i][j];
                if(curr == '0'){
                    count = 0;
                    continue;
                }
                if(curr == last){
                    count += 1;
                } else{
                    if(count >= 3){
                        markCol(j, i - 1, count, mark);
                    }
                    last = curr;
                    count = 1;
                }
            }
            if(count >= 3)
                markCol(j, rows - 1, count, mark);
        }
    }

    private static void markRow(int row, int end, int count, boolean[][] mark){
        for(int j = end; j > end - count; j--){
            mark[row][j] = true;
        }
    }

    private static void markCol(int col, int end, int count, boolean[][] mark){
        for(int i = end; i > end - count; i--){
            mark[i][col] = true;
        }
    }
}

第一题 字符串
import javafx.util.Pair;

import java.util.HashMap;
import java.util.Scanner;

public class Main {
    private static HashMap<Character, Integer> hashMap = new HashMap<>();
    private static String dictionary = "";

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String text = scanner.nextLine();
        scanner.close();

        initDictionary();

        String result = getString(text, 1);
//        System.out.println(result);
        System.out.println(getMostAlpha(result));
    }

    private static void initDictionary() {
        StringBuilder stringBuilder = new StringBuilder();

        int index = 0;
        for (char i = 'A'; i <= 'Z'; i++) {
            hashMap.put(i, index++);
            stringBuilder.append(i);
        }

        for (char i = 'a'; i <= 'z'; i++) {
            hashMap.put(i, index++);
            stringBuilder.append(i);
        }

        dictionary = stringBuilder.toString();
    }

    private static String getMostAlpha(String text){
        text = text.toLowerCase();

        int max = 0;
        char maxAlpha = '!';
        HashMap<Character, Integer> map = new HashMap<>();
        for(int i = 0; i < text.length(); i++){
            char ch = text.charAt(i);
            if(map.containsKey(ch))
                map.put(ch, map.get(ch) + 1);
            else
                map.put(ch, 1);
            if(map.get(ch) > max) {
                max = map.get(ch);
                maxAlpha = ch;
            }
        }

        return String.valueOf(maxAlpha) + max;
    }

    private static String getString(String text, int count) {
        StringBuilder result = new StringBuilder();
        StringBuilder last = new StringBuilder();
        int index = 0;
        while (index < text.length()) {
            char curr = text.charAt(index);
            if (curr >= '0' && curr <= '9') {
                int start = index++;
                while (index < text.length() && text.charAt(index) >= '0' && text.charAt(index) <= '9') {
                    index++;
                }
                int number = Integer.parseInt(text.substring(start, index)) - 1;
                for(int i = 0; i < number; i++){
                    result.append(last.toString());
                }
                last.delete(0, last.length());
            } else if (index < text.length() - 2 && text.charAt(index + 1) == '-') {
                int start = hashMap.get(curr);
                int end = hashMap.get(text.charAt(index + 2));
                result.append(dictionary.substring(start, end + 1));
                last.append(dictionary.substring(start, end + 1));
                index += 3;
            } else {
                result.append(curr);
                last.append(curr);
                index += 1;
            }
        }
        String s = "";
        for (int i = 0; i < count; i++) {
            s += result.toString();
        }
        return s;
    }
}

真的不强
牛友回我tql 我都觉得自己要飘了😂
运气好,手感好而已
迄今0offer😂
每天坚持来牛客许愿



#笔试题目##米哈游#
全部评论
你这两个题总共写了近250行代码啊,厉害了
点赞 回复 分享
发布于 2019-09-12 21:31
666大佬大佬
点赞 回复 分享
发布于 2019-09-07 20:51
哥 你真猛
点赞 回复 分享
发布于 2019-09-07 20:48
大佬
点赞 回复 分享
发布于 2019-09-07 20:31
TDL!!
点赞 回复 分享
发布于 2019-09-07 20:26
太强了
点赞 回复 分享
发布于 2019-09-07 20:26
老哥tql
点赞 回复 分享
发布于 2019-09-07 20:26

相关推荐

是腾讯的csig腾讯云,前天晚上九点突然打电话约面,激动的通宵学了一晚上,第二天状态很差改了今天(以后再也不通宵学习了)感觉自己浪费了面试官一个半小时单纯手写+场景,无八股无项目无算法,打击真的很大,全是在面试官提醒的情况下完成的,自己技术方面真的还是有待提高,实力匹配不上大厂和已经面试的两个公司完全不一样,很注重编码能力和解决问题的能力,然而我这两个方面都很薄弱,面试官人很好很耐心的等我写完题目,遇到瓶颈也会提醒我,写不出题也会很耐心的跟我讲解好感动,到最后面试结束还安慰我打算把下周最后一场面试面完之后就不面啦,如果能去实习还是很开心,但是最重要的还是好好努力提高技术以下是面经第一题//&nbsp;实现一个解析&nbsp;url&nbsp;参数的函数function&nbsp;parseUrl(urlStr)&nbsp;{//&nbsp;TODO}parseUrl('*********************************************');//&nbsp;返回&nbsp;{a:&nbsp;1,&nbsp;b:&nbsp;2,&nbsp;c:&nbsp;3}追问:在链接里见过什么部分?用&nbsp;hash&nbsp;路由的话放在哪第二题//&nbsp;考虑有一个异步任务要执行,返回&nbsp;Promise,这个任务可能会失败,请实现&nbsp;retry&nbsp;方法,返回新方法,可以在失败后自动重试指定的次数。/***&nbsp;异步任务重试*&nbsp;@param&nbsp;task&nbsp;要执行的异步任务*&nbsp;@param&nbsp;times&nbsp;需要重试的次数,默认为&nbsp;3&nbsp;次*/function&nbsp;retry(task,&nbsp;times&nbsp;=&nbsp;3)&nbsp;{//&nbsp;TODO:&nbsp;请实现}//&nbsp;---------------测试示例&nbsp;----------------//&nbsp;原方法const&nbsp;request&nbsp;=&nbsp;async&nbsp;(data)&nbsp;=&gt;&nbsp;{//&nbsp;模拟失败if&nbsp;(Math.random()&nbsp;&lt;&nbsp;0.7)&nbsp;{throw&nbsp;new&nbsp;Error('request&nbsp;failed');}const&nbsp;res&nbsp;=&nbsp;await&nbsp;fetch(&#39;https://jsonplaceholder.typicode.com/posts&#39;,&nbsp;{method:&nbsp;'POST',body:&nbsp;JSON.stringify(data),});return&nbsp;res.json();}//&nbsp;新的方法const&nbsp;requestWithRetry&nbsp;=&nbsp;retry(request);//&nbsp;使用async&nbsp;function&nbsp;run()&nbsp;{const&nbsp;res&nbsp;=&nbsp;await&nbsp;requestWithRetry({&nbsp;body:&nbsp;'content'&nbsp;});console.log(res);}run();第三题就是给&nbsp;retry&nbsp;函数添加类型注释,用到泛型第四题:在组件库中将&nbsp;Alert&nbsp;用&nbsp;api&nbsp;的形式实现(应该就是&nbsp;message&nbsp;这个组件)怎么渲染到一个浮层里而不是原地渲染出来
不知道怎么取名字_:技术这个东西,太杂了,而且要下功夫的
查看5道真题和解析
点赞 评论 收藏
分享
回家当保安:复旦✌🏻,佬你的简历感觉挺好的,寒假日常hc比较少。佬可以过完年之后再试试,日常实习hc比较充足
点赞 评论 收藏
分享
12-27 22:29
门头沟学院 Java
点赞 评论 收藏
分享
评论
6
11
分享

创作者周榜

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