The pinyin to the number of a question

Source: Internet
Author: User

Input is a string containing only pinyin, please output the corresponding number sequence. The conversion relationship is as follows: Description: Pinyin yi er san si wu Liu Qi ba jiu Arabic numerals 1 2 3 4 5 6 7 8 9 The input characters contain only lowercase letters, and all characters can match exactly
Run time limit: Unlimited memory limit: Unlimited input: One line of string, less than 1000 length output: One line character (number) string Sample input: Yiersansi sample output: 1234
Ideas: 1) < Pinyin, number > as key pair, save in HashMap 2) string loop, take out the number of the response from the HashMap
Java Solution: Import Java.util.hashmap;import Java.util.Scanner;
public class main{public static void Main (string[] args) {
Scanner cin=new Scanner (system.in);  Hashmap<string, integer> hashmap=new hashmap<> ();  Hashmap.put ("Yi", 1);  Hashmap.put ("ER", 2);  Hashmap.put ("San", 3);  Hashmap.put ("Si", 4);  Hashmap.put ("WU", 5);  Hashmap.put ("Liu", 6);  Hashmap.put ("Qi", 7);  Hashmap.put ("Ba", 8); Hashmap.put ("JIU", 9);
While
(Cin.hasnext ()) {
func (HashMap, Cin.next ());
Break
;
  }
} public static void Func (Hashmap<string, integer> HashMap, String str) {
int k1=0;  int k2=2;  System.out.println (Hashmap.get ("111")); while (K2<=str.length ()) {
if (Hashmap.get (Str.subsequence (K1, K2))!=null)
{
System.out.print (Hashmap.get (str.subsequence (K1, K2)));
}
else {
k2++;
if (Hashmap.get (Str.subsequence (K1, K2))!=null)
    {
System.out.print (Hashmap.get (str.subsequence (K1, K2)));
    }
   }
K1=k2;
k2+=2;
  } }
}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The pinyin to the number of a question

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.