0
点赞
收藏
分享

微信扫一扫

MATLAB 统计滤波(去除点云噪声)(55)

萨科潘 03-31 14:30 阅读 1

目录

题目描述 

思路

代码实现

题目描述 

思路

统计字符串不同字符的个数,其实就是对一个字符数组去重,可以使用Set集合

代码实现

     public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            // 使用HashSet来存储出现过的不同字符,自动去重
            String s = sc.nextLine();
            Set<Character> distinctChars = new HashSet<>();

            for (char c : s.toCharArray()) {
                // 只处理ASCII码在0~127范围内的字符
                if (c >= 0 && c <= 127 && c != '\n') {
                    distinctChars.add(c);
                }
            }
            System.out.print(distinctChars.size());
        }
    }
举报

相关推荐

0 条评论