飞道的博客

【JAVA】vivo2021届秋季校招笔试在线编程

443人阅读  评论(0)

前言

兄弟们都会有offer的,不要慌,奥力给

一、游戏地图路径(没尝试,时间不够,我对最短路径问题不熟)

二、回文字符串(A0.8,逻辑混乱了)

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");
        }
    }
}

三、编译依赖问题(全A)

package vivo;

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

/**
 * Created by IntelliJ IDEA.
 *
 * @Author: 张志浩 Zhang Zhihao
 * @Email: 3382885270@qq.com
 * @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);
    }
}

转载:https://blog.csdn.net/weixin_43124279/article/details/108555861
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场