2015 Huawei trial-print the number of different characters in the string, 2015 Huawei
Description:
Find the number of different characters in the string.
Question type: String
Difficulty: elementary
Running time limit: Unlimited
Memory limit: Unlimited
Stage: Pre-Employment exercises
Input:
Enter a string, '\ 0' as the string Terminator.
Output:
Number of different characters in the output string.
Sample input:
122345
Sample output:
5
The Code is as follows:
Public class dayin_Char {public static void main (String [] args) {nation SC = new Nation (System. in); while (SC. hasNext () {String input = SC. nextLine (); if (input = null) {return;} int count = 0; Map <Integer, Character> hm = new HashMap <Integer, Character> (); for (int I = 0; I <input. length (); I ++) {if (! Hm. containsValue (input. charAt (I) {count ++; hm. put (I, input. charAt (I) ;}} System. out. println (count );}}}
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.