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