[JAVA] Programación en línea de la prueba escrita de reclutamiento de la escuela de otoño de Vivo2021

Prefacio

Los hermanos tendrán ofertas, no te asustes, Aoli te dará

Inserte la descripción de la imagen aquí

1. La ruta del mapa del juego (no lo intenté, no hay suficiente tiempo, no estoy familiarizado con el problema de la ruta más corta)

2. Cadena de palíndromo (A0.8, la lógica es confusa)

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. Problema de dependencia de la compilación (todos 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);
    }
}

Supongo que te gusta

Origin blog.csdn.net/weixin_43124279/article/details/108555861
Recomendado
Clasificación