[Programming questions] Two sorts of sorting methods

Source: Internet
Author: User
Tags sorts

Small, easy-to-like words have the following characteristics:
1. Words each letter is uppercase
2. Words have no consecutive equal letters
3. The word is not shaped like "Xyxy" (where x, y refers to a letter, and can be the same) such a subsequence, the subsequence may be discontinuous.
For example:
Xiao Yi does not like "ABBA", because there are two consecutive ' B '
Xiao Yi does not like "thetxh", because this contains the subsequence "Thth"
Xiao Yi doesn't like "Abacada" because it contains sub-sequence "AAAA"
Small easy to Like "A", "ABA" and "ABCBA" these words
Give you a word, you have to answer whether Xiao Yi will like the word.

Import java.util.*;import java.lang.*;import java.math.*;import java.text.*;p ublic class Main {public static String        Fun (String str) {hashmap<character,integer> mp1= new HashMap ();        hashmap<character,integer> mp2= new HashMap ();        Char[] Ch=str.tochararray ();            for (int i=0;i<str.length (); ++i) {if (i>0&&ch[i]==ch[i-1]) return "dislikes"; if (ch[i]< ' A ' | |            Ch[i]> ' Z ') return "dislikes";            if (!mp1.containskey (ch[i))) Mp1.put (ch[i],i);                else{Iterator Iter=mp2.keyset (). Iterator ();                    while (Iter.hasnext ()) {Object key = Iter.next ();                    int val = mp2.get (key);                    if (Mp1.get (key) <mp1.get (Ch[i]) && (Val>mp1.get (Ch[i])) {return "dislikes";            }} mp2.put (Ch[i],i);    }} return "likes";  }  public static void Main (string[] args) {Scanner sc=new Scanner (system.in);            while (Sc.hasnext ()) {String str=sc.nextline ();        System.out.println (str); }    }}

[Programming questions] two sort methods

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.