输入一行没有空格的字符串。
输出 输入字符串 中范围在(0~127,包括0和127)字符的种数。
abc输出:
3
aaa输出:
1
方法一:
1 import java.io.*; 2 import java.util.*; 3 4 public class Main { 5 public static void main(String[] args) throws IOException { 6 BufferedReader br = new BufferedReader(new InputStreamReader((System.in))); 7 String s; 8 while((s = br.readLine()) != null) { 9 String newS = ""; 10 for (int i = s.length()-1; i>=0; i--){ 11 char ch = s.charAt(i); 12 if( newS.indexOf(ch) < 0){ 13 newS = newS + ch; 14 } 15 } 16 System.out.println(newS.length()); 17 } 18 } 19 }
方法二:
1 import java.io.*; 2 import java.util.*; 3 4 public class Main { 5 public static void main(String[] args) throws IOException { 6 BufferedReader br = new BufferedReader(new InputStreamReader((System.in))); 7 String s = br.readLine(); 8 int[] a = new int[128]; 9 int count = 0; 10 for (int i=0; i<s.length();i++){ 11 char ch =s.charAt(i); 12 if(a[ch] == 0){ 13 count =count +1; 14 a[ch] = 1; 15 } 16 } 17 System.out.println(count); 18 } 19 }