HDU 1113 word amalgamation (MAP container + String container)

Source: Internet
Author: User

Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1113


Problem description

In millions of newspapers initialize ss the United States there is a word game called jumble. the object of this game is to solve a riddle, but in order to find the letters that appear in the answer it is necessary to 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 at least one and at most 100 words, one per line;
2. A line containing xxxxxx, which signals the end of the dictionary;
3. One or more scrambled 'word' that you 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 English letters and will be at least one and at most six characters long. (note that the Sentinel xxxxxx contains uppercase X's .) the dictionary is not necessarily in sorted order, but each word in the dictionary is unique.


Output

For each scrambled word in the input, output an alphabetical list of all dictionary words that can be formed by rearranging the letters in the scrambled word. each word in this list must appear on a line by itself. if the list is empty (because no dictionary words can be formed), output 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
Nfudh
Aptr
Sett
Oresuc
Xxxxxx


Sample output

Score
******
Refund
******
Part
Tarp
Trap
******
Not a valid word
******
Course
******


Question: Let's use some words as a dictionary to find out whether these words exist in a series of words (note that the alphabetic order of a word can be changed, that is to say, words must be output in the same order as long as the letters are the same.) If no single word in the dictionary has the same letters, "not a valid word" is output ", and each time, a line "*******" is generated.


Solution:

A map container is a one-to-one vector container (understanding http://blog.csdn.net/keshacookie/article/details/19847781)

>>> First, a series of dictionary words are added to the end of "xxxxxx". These words are used as the vector front end (the back end is also good, personal preferences, don't worry about it.) When each dictionary contains a single word, save the original words of the word, and then sort the words, the words in the order form the back end of the vector;

>>> Then, encrypt the encrypted words and sort them first, then compare the back end of the dictionary word vector stored in the map (once again, it will be OK );

>>> You can just export the corresponding response;


The token generation is as follows:

# include # include # include # include # include // Add a map header file # include # include # define RST (N) memset (n, 0, sizeof (N) using namespace STD; int flag; string S1, S2; // string container; Map MP; // map container Map : iterator it; // map iterator int main () {MP. clear (); // clear the map container while (CIN> S1) {// empty the dictionary words if (S1 = "xxxxxx") break; S2 = S1; // Save the original words such as repeated orders sort (s1.begin (), s1.end (); MP [s2] = S1; // S1, S2 form a vector, saved token in map container} while (CIN> S1) {// encrypt the encrypted word if (S1 = "xxxxxx") break; flag = 0; sort (s1.begin (), s1.end (); For (IT = MP. begin (); it! = MP. end (); It ++) {// times faster, and returns string TMP = (* it ). second; // in map, the first and second points represent the front and back ends of the vector if (S1 = TMP) {cout <(* it ). first



HDU 1113 word amalgamation (MAP container + String container)

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.