字符统计个数

字符个数统计

http://www.nowcoder.com/questionTerminal/eb94f6a5b2ba49c6ac72d40b5ce95f50

import java.io.*;
import java.util.*;

public class Main{
    public static void main(String[] args) throws Exception{
        Scanner sc = new Scanner(System.in);
        while(sc.hasNextLine()){
            String s = sc.nextLine();
            char[] cc = s.toCharArray();
            int count = 0;
            HashSet<Character> set = new HashSet<>();
            for(int i = 0; i < cc.length; ++i){
                if(cc[i] >= 0 && cc[i] <= 127){
                    if(!set.contains(cc[i])){
                        set.add(cc[i]);
                        count++;
                    }
                }
            }
            System.out.println(count);
        }
    }
}
全部评论
已经用了HashSet了,还!set.contains(cc[i])干嘛
1 回复 分享
发布于 2023-03-23 15:51 山西
已经用了HashSet了,还int count干嘛?
点赞 回复 分享
发布于 2024-01-11 23:37 北京

相关推荐

后来123321:别着急,我学院本大二,投了1100份,两个面试,其中一个还是我去线下招聘会投的简历,有时候这东西也得看运气
无实习如何秋招上岸
点赞 评论 收藏
分享
评论
13
2
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务