记录小红书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;
    }
}
全部评论

相关推荐

nbdy:字太多了,写简历不是写自传,亮点难点技能点列出来就行,要简明扼要
点赞 评论 收藏
分享
2024-12-21 10:42
已编辑
江西软件职业技术大学 Java
新宿站不停:该提升学历就提升学历,菜了就多练。没事找牛马公司虐自己是吧? 谁没事说自己“经验少”,这不自己把自己塞剎鼻hr嘴里找🐴吗
点赞 评论 收藏
分享
评论
3
4
分享

创作者周榜

更多
牛客网
牛客企业服务