HDOJ/HDU 1113 Word Amalgamation (dictionary order ~map)

Source: Internet
Author: User

Problem Description
In millions of newspapers across the and states there is a word game called Jumble. The object of this game was to solve a riddle, but in order to find the letters that appear in the answer it's necessary t O unscramble four words. Your task is to write a program that can unscramble words.

Input
The input contains four parts:

    1. A dictionary, which consists of least one and at the most of the words, one per line;
    2. A line containing XXXXXX, which signals the end of the dictionary;
    3. One or more scrambled ' words ' this must unscramble, each on a line by itself; and
    4. Another line containing XXXXXX, which signals the end of the file.

All words, including both dictionary words and scrambled words, consist only of lowercase 中文版 letters and'll be at L East one and at the most six characters long. (Note that the Sentinel XXXXXX contains uppercase X ' s.) The dictionary is not necessarily in sorted order, and each word in the dictionary is unique.

Output
For each scrambled word in the input, output a alphabetical list of all dictionary words, can is formed by rearrangin G The letters in the scrambled word. Each of the word in this list must appear on a line by itself. If the list is empty (because no dictionary words can be formed), the output of the line "not A VALID WORD" instead. In either case, output a line containing six asterisks to signal the end of the list.

Sample Input
Tarp
Given
Score
Refund
Only
Trap
Work
Earn
Course
Pepper
Part
Xxxxxx
Resco
Nfudre
Aptr
Sett
Oresuc
Xxxxxx

Sample Output

score******refund******parttarptrap******NOT A VALID WORD******course******

Test instructions
Input dictionary xxxxxx end Dictionary input and then enter A string if the string is able to make up a string in the dictionary, output the string otherwise output not A VALID WORD
is to find a string in the dictionary that consists of the same letter.
(Find the string if there are many, to be output in dictionary order!) )

ImportJava.util.ArrayList;ImportJava.util.Arrays;ImportJava.util.Comparator;ImportJava.util.HashMap;ImportJava.util.List;ImportJava.util.Map;ImportJava.util.Scanner;/** * @author Chen Haoxiang * 2016-5-27 * * Public  class Main{     Public Static void Main(string[] args) {Scanner SC =NewScanner (system.in); while(Sc.hasnext ()) {String str=""; String chstr=""; map<string, list<string>> map =NewHashmap<string, list<string>> (); while(true) {List<string> List =NewArraylist<string> (); Str=sc.next ();if("XXXXXX". Equals (str)) { Break; }CharCh[] = Str.tochararray ();                Arrays.sort (CH); Chstr=NewString (CH);if(Map.get (chstr) = =NULL) {List.add (str);                Map.put (CHSTR, list); }Else{list = Map.get (CHSTR);                    List.add (str);                Map.put (CHSTR, list); }            } while(true) {Str=sc.next ();if("XXXXXX". Equals (str)) { Break; }CharCh[] = Str.tochararray ();                Arrays.sort (CH); Chstr=NewString (CH); list<string> list = Map.get (CHSTR);if(list==NULL) {System.out.println ("not A VALID WORD"); }Else{String strs[] =NewString[list.size ()]; for(intI=0; I<list.size (); i++) {strs[i]=list.get (i); } arrays.sort (STRs,NewComparator<string> () {@Override                         Public int Compare(String O1, String O2) {returnO1.compareto (O2); }                    }); for(intI=0; i<strs.length;i++) {System.out.println (strs[i]); }} System.out.println ("******"); }        }    }}

HDOJ/HDU 1113 Word Amalgamation (dictionary order ~map)

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.