Hdoj Title Address: Portal
Word AmalgamationTime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total Submission (s): 3493 Accepted Submission (s): 1708
Problem DescriptionIn millions of newspapers across the all 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.
Inputthe 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.
Outputfor each scrambled word in the input, output a alphabetical list of all dictionary words, can is formed by rear Ranging 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
Tarpgivenscorerefundonlytrapworkearncoursepepperpartxxxxxxresconfudreaptrsettoresucxxxxxx
Sample Output
Score******refund******parttarptrap******not A VALID word******course******
#include <stdio.h> #include <string.h> #include <map> #include <iostream> #include < Algorithm>using namespace std;map<string,string> m;string s,str;int main () {while (cin>>s) { if (s== "XXXXXX") break ; Str=s; Sort (S.begin (), S.end ()); m[str]=s; } while (cin>>s) { if (s== "XXXXXX") is break ; Sort (S.begin (), S.end ()); Map<string,string>::iterator it; int flag=0; For (It=m.begin (); It!=m.end (); it++) { if (it->second==s) { flag=1; cout<<it->first<<endl; } } if (!flag) cout<< "not A VALID WORD" <<endl; cout<< "******" <<endl; }}
acm--string--hdoj 1113--word amalgamation--map