2020年5月牛客模考编程题

  public void get(){
        Scanner scanner = new Scanner(System.in);
        String string = scanner.next();
        int length = string.length();
        int ans = 0,temp_length = 0;
        boolean flag = true;
//        长度为2时,输出0
        if (length == 2 ){
            System.out.println(ans);
            return;
        }

        for (int i = 2; i <= length ; i += 2) {
            flag = true;
            string = string.substring(0, length - i);
            temp_length = length - i;
            for (int j = 0; j < temp_length / 2; j++) {
                if (string.charAt(j) != string.charAt(temp_length / 2 + j)){
                    flag = false;
                    break;
                }
            }
            if (flag){
                System.out.println(temp_length);
                return;
            }
        }
        System.out.println(ans);
        return;
    }
    public void show(){
        HashMap<Character,Integer> map = new HashMap<>();
        Scanner scanner = new Scanner(System.in);
        String str = scanner.next();
        int ans = 0;
        for (int i = 0; i < str.length(); i++) {
            Character ch = (Character) str.charAt(i);
            if (map.containsKey(ch)){
                map.put(ch,map.get(ch) + 1);
            }
            else {
                map.put(ch,1);
            }
        }
        Collection<Integer> values = map.values();
        Iterator<Integer> iterator = values.iterator();
        while (iterator.hasNext()){
            Integer tmp = iterator.next();
            if (tmp % 2 == 1){
                ans ++;
            }
        }
        System.out.println(ans);
    }
全部评论

相关推荐

10-17 12:16
同济大学 Java
7182oat:快快放弃了然后发给我,然后让我也泡他七天最后再拒掉,狠狠羞辱他一把😋
点赞 评论 收藏
分享
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务