记录小红书8.19笔试(暴力)

1.小红背单词

public class Main1 {

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

        int count = 1;
        HashMap<String, Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            String word = scanner.nextLine();
            int value = map.getOrDefault(word, 0) + 1;
            map.put(word,value);
            if (value == count){
                map.put(word,Integer.MIN_VALUE);
                count++;
            }
        }
        System.out.println(count-1);
    }
}

2.判断回文串

public class Main2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        scanner.nextLine();

        for(int i = 0;i < n;i++){
        	String str = scanner.nextLine();
        	char[] strArray = str.toCharArray();
        	boolean is = method(strArray);
        	String result = is ? "YES" : "NO";
        	System.out.println(result);
        }
    }

    private static boolean method(char[] strArray) {
        ArrayList<Character> list = new ArrayList<>();
        for (int i = 0; i < strArray.length; i++) {
            if (strArray[i] == 'm') {
                list.add('u');
                list.add('u');
            }else if (strArray[i] == 'w') {
                list.add('v');
                list.add('v');
            }else if (strArray[i] == 'b' || strArray[i] == 'p' || strArray[i] == 'q' || strArray[i] == 'd') {
                list.add('b');//p  q  d  都行
            }else if (strArray[i] == 'u' || strArray[i] == 'n') {
                list.add('u');
            }else {
                list.add(strArray[i]);
            }
        }
        for (int i = 0, j = list.size() - 1; i < j; i++, j--) {
            if (list.get(i) != list.get(j)) {
                return false;
            }
        }
        return true;
    }
}
全部评论

相关推荐

点赞 评论 收藏
分享
某牛奶:一觉醒来全球程序员能力下降200%,小伙成功scanf惊呆在座个人。
点赞 评论 收藏
分享
Java抽象带篮子:难蚌,点进图片上面就是我的大头😆
点赞 评论 收藏
分享
3 4 评论
分享
牛客网
牛客企业服务