[JAVA] Vivo2021 Fall School Recruitment Written Test Online Programming

Preface

Brothers will have offers, don’t panic, Aoli will give

Insert picture description here

1. The game map path (didn't try, there is not enough time, I am not familiar with the shortest path problem)

2. Palindrome string (A0.8, logic is confused)

package vivo;

import java.util.Scanner;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author: 
 * @Email: 
 * @Date: 2020/9/12
 * @Time: 20:31
 * @Version: 1.0
 * @Description: Description
 */

/**
 * 1. 游戏地图路径
 * 2. 回文字符串
 * 3. 编译依赖问题
 */
public class Second {
    
    
    public static void main(String[] args) {
    
    
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        vaild(str);
        sc.close();
    }

    public static void vaild(String s) {
    
    
        int low = 0, high = s.length() - 1;
        boolean flag1 = true;
        boolean flag2 =true ;
        while (low < high) {
    
    
            char c1 = s.charAt(low);
            char c2 = s.charAt(high);
            if (c1 == c2) {
    
    
                low++;
                high--;
            } else {
    
    
                flag1 = true;
                flag2 = true;
                for (int i = low, j = high - 1; i < j; i++, j--) {
    
    
                    char c3 = s.charAt(i);
                    char c4 = s.charAt(j);
                    if (c3 != c4) {
    
    
                        flag1 = false;
                        break;
                    }
                }
                for (int i = low + 1, j = high; i < j; i++, j--) {
    
    
                    char c3 = s.charAt(i);
                    char c4 = s.charAt(j);
                    if (c3 != c4) {
    
    
                        flag2 = false;
                        break;
                    }
                }

                if (!flag2) {
    
    
                    System.out.println(s.substring(0, low) + s.substring(low + 1));
                    return;
                } else if (!flag1) {
    
    
                    System.out.println(s.substring(0, high) + s.substring(high + 1));
                    return;
                } else {
    
    
                    break;
                }
            }

        }
        if (flag1 && flag2) {
    
    
            System.out.println(s);
        } else {
    
    
            System.out.println("false");
        }
    }
}

3. Compilation dependency problem (all A)

package vivo;

import java.util.HashSet;
import java.util.Iterator;
import java.util.TreeMap;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author: 张志浩 Zhang Zhihao
 * @Email: [email protected]
 * @Date: 2020/9/12
 * @Time: 21:41
 * @Version: 1.0
 * @Description: Description
 */
 
public class Third2 {
    
    
    public static void main(String[] args) {
    
    
        System.out.println(new Third2().compileSeq("1,2,-1,1"));
    }

    public String compileSeq(String input) {
    
    
        String[] strList = input.split(",");
        TreeMap<Integer, Integer> yiLai = new TreeMap<Integer, Integer>();
        for (int i = 0; i < strList.length; i++) {
    
    
            yiLai.put(i, Integer.parseInt(strList[i]));
        }

        HashSet<Integer>[] lasts = new HashSet[2];
        lasts[0] = new HashSet<Integer>();
        lasts[1] = new HashSet<Integer>();
        int lastIndex = 0;
        lasts[lastIndex].add(-1);

        StringBuilder result = new StringBuilder();
        while (!yiLai.isEmpty()) {
    
    
            Iterator<Integer> iterator = yiLai.keySet().iterator();
            while (iterator.hasNext()) {
    
    
                int integer = iterator.next();
                if (lasts[lastIndex].contains(yiLai.get(integer))) {
    
    
                    result.append(integer);
                    result.append(",");
                    iterator.remove();
                    lasts[(lastIndex + 1) % 2].add(integer);
                }
            }
            lastIndex = (lastIndex + 1) % 2;
        }
        return result.substring(0, result.length() - 1);
    }
}

Guess you like

Origin blog.csdn.net/weixin_43124279/article/details/108555861