题解 | #字符个数统计#

字符个数统计

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

import java.util.HashSet;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            String str = sc.nextLine();
            char[] arr = str.toCharArray();
            HashSet<Character> hashS = new HashSet<>();
            int count = 0;
            for (int i = 0; i < arr.length; i++) {
                if(arr[i] >= 0 && arr[i] <= 127){
                    if (hashS.add(arr[i])){
                        count++;
                    }
                }
            }
            System.out.println(count);

        }

    }
}
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-01 12:22
点赞 评论 收藏
分享
在debug的柠檬精...:好消息:现在HR挑三拣四 15年后 HR跪着求要简历 坏消息:被挑的是这代人,到时候求人的也是这代人。真好。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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