2015 Huawei trial-print the number of different characters in the string, 2015 Huawei

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.