import java.util.*;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
String str = in.nextLine();
Set<Character> set = new HashSet<Character>();
for(int i = 0;i<str.length();i++){
set.add(str.charAt(i));
}
if(set.size()==1) System.out.println(1);
else if(set.size()==2) System.out.println(2);
else System.out.println(0);
}
}
使用set元素去重,然后分析set中不重复的元素个数。

京公网安备 11010502036488号