Word Amalgamation
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 2845 Accepted Submission (s): 1369
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 Inputtarp given score refund only trap work earn course pepper Part XXXXXX Resco nfudre aptr sett oresuc XXXXXX
Sample outputscore ****** refund ****** part tarp trap ****** not A VALID WORD ****** course ******
Sourcemid-central USA 1998
Recommendeddy | We have carefully selected several similar problems for you:1073 1075 1039 1062 1088 <1> input several strings, (sorted by dictionary order) → use as a dictionary; < ;2> input unordered words, find;<3> output;
1#include <stdio.h>2#include <string.h>3#include <algorithm>4 using namespacestd;5 6 structDiC7 {8 intN;9 Charstr[Ten]; Ten }; OneDiC num[ the]; A - BOOLcmpCharCCharb) - { the returnC >b; - } - - BOOLCPM (DiC str, dic N) + { - returnstrcmp (STR.STR, N.STR) <0; + } A intMain () at { - Charch[Ten]; - Chars[Ten]; - Charac[ the][Ten]; - intI, j,total=0; - while(~SCANF ("%s", ch) &&strcmp (CH,"XXXXXX")!=0) in { -strcpy (num[total++].str, ch); to //i++; + } -Sort (num, num+Total , CPM); the //printf ("%d\n", total); * while(~SCANF ("%s", ch), strcmp (CH,"XXXXXX")!=0) $ {Panax Notoginseng intflag=0, Len; - intNel=strlen (CH); theSort (CH, ch+Nel, CMP); + for(i=0; i<=total; i++) A { the strcpy (S, num[i].str); +Len =strlen (s); -Sort (S, s+Len, CMP); $ if(strcmp (s, ch) = =0) $ { -printf"%s\n", num[i].str); -flag++; the } - //ElseWuyi //printf ("Not A VALID word\n"); the } - if(flag==0) Wuprintf"Not A VALID word\n"); - /*Else About { $ sort (AC,AC+FLAG,CPM); - For (i=0; i<flag; i++) - printf ("%s", Ac[i]); - }*/ Aprintf"******\n"); + } the return 0; -}
Hangzhou Electric 1113--word Amalgamation