题解 | 字符个数统计
字符个数统计
https://www.nowcoder.com/practice/eb94f6a5b2ba49c6ac72d40b5ce95f50
import java.util.*;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNext()) {
String str=in.nextLine();
Set res=new HashSet();
for(int i=0;i<str.length();i++){
if(str.charAt(i)-'!'>=0&&str.charAt(i)-'!'<=93){
res.add(str.charAt(i)-'!');
}
}
System.out.println(res.size());
}
}
}
思路挺简单的,就是用任何有去重作用的数据结构做记录就行,我用了hashset,存的是对应ascaii码的数值在33-126之间也就是对应的0到93

