杭电1113--Word Amalgamation

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 Description

In millions of newspapers across 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 `words‘ 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

nfudre

aptr

sett

oresuc

XXXXXX

Sample Output

score

******

refund

******

part

tarp

trap

******

NOT A VALID WORD

******

course

******

Source

Mid-Central USA 1998

Recommend

Eddy   |   We have carefully selected several similar problems for you:  1073 1075 1039 1062 1088

<1>输入几个字符串,(按字典序排好)→ 用作字典;

<2>输入无序单词,查找;

<3>输出;

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <algorithm>
 4 using namespace std;
 5
 6 struct dic
 7 {
 8     int n ;
 9     char str[10];
10 };
11 dic num[110];
12
13 bool cmp(char c, char b)
14 {
15     return c > b;
16 }
17
18 bool cpm(dic str, dic n)
19 {
20     return strcmp(str.str, n.str) < 0;
21 }
22 int main()
23 {
24     char ch[10];
25     char s[10];
26     char ac[110][10];
27     int i, j,total=0;
28     while(~scanf("%s",ch)&&strcmp(ch, "XXXXXX")!=0)
29     {
30         strcpy(num[total++].str, ch);
31         //i++;
32     }
33     sort(num, num+total, cpm);
34     //printf("%d\n", total);
35     while(~scanf("%s",ch),strcmp(ch, "XXXXXX")!=0)
36     {
37         int flag=0 ,len;
38         int nel=strlen(ch);
39         sort(ch, ch+nel, cmp);
40         for(i=0; i<=total; i++)
41         {
42                strcpy(s, num[i].str);
43             len = strlen(s);
44             sort(s, s+len, cmp);
45             if(strcmp(s, ch) == 0)
46             {
47                 printf("%s\n", num[i].str);
48                 flag++;
49             }
50             //else
51             //printf("NOT A VALID WORD\n");
52         }
53         if(flag==0)
54         printf("NOT A VALID WORD\n");
55           /*else
56         {
57             sort(ac,ac+flag,cpm);
58             for(i=0; i<flag; i++)
59             printf("%s", ac[i]);
60         }*/
61         printf("******\n");
62     }
63     return 0;
64 }
时间: 2024-10-12 08:38:14

杭电1113--Word Amalgamation的相关文章

hdu 1113 Word Amalgamation (map)

# include <stdio.h> # include <string> # include <map> # include <iostream> # include <algorithm> using namespace std; int main() { string s,t; int flag; map<string,string>q; while(cin>>s&&s!="XXXXXX&

HDU 1113 Word Amalgamation (map 容器 + string容器)

http://acm.hdu.edu.cn/showproblem.php?pid=1113 Problem Description In millions of newspapers across 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 th

hdu - 1113 Word Amalgamation (stl)

http://acm.hdu.edu.cn/showproblem.php?pid=1113 给定一个字典,然后每次输入一个字符串问字典中是否有单词与给定的字符串的所有字母一样(顺序可以打乱),按字典序输出字典中的原字符串. 我开始是直接用了 sort, 用一个结构体记录了所有字符串,和相应下标,输出的时候在用了冒泡排序. 1 #include <iostream> 2 #include <cstdio> 3 #include <cmath> 4 #include &l

HDOJ/HDU 1113 Word Amalgamation(字典顺序~Map)

Problem Description In millions of newspapers across 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 wor

hdu1113 Word Amalgamation(超详细解释--map和string的运用)

转载请注明出处:http://blog.csdn.net/u012860063天资 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1113 来吧!!欢迎"热爱编程"的同学报考杭电,期待你加入"杭电ACM集训队"! 7月22-8月21多校联合训练期间,会根据实际负载关闭部分模块,若有不便,请谅解~ Word Amalgamation Time Limit: 2000/1000 MS (Java/Others)    Me

杭电ACM分类

杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDIATE DECODABILITY

【转】对于杭电OJ题目的分类

[好像博客园不能直接转载,所以我复制过来了..] 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDI

杭电ACM题目分类

杭电ACM题目分类 基础题:1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028. 1029.1032.1037.1040.1048.1056.1058.1061.1070.1076.1089.1090.1091.1092. 1093.1094.1095.1096.1097.1098.1106.1108.1157.1163.1164.1170.1194.1196. 1197.1201.1202.1205.1219.1234.123

hdu1702(ACboy needs your help again!) 在杭电又遇坑了

点击打开链接 结题感悟: 其实吧,这题并不是很难,就是一个栈和队列的公共题,也就是按指定的方式(栈或队列)存取数据,但是为什么我自己写的栈和队列就是不能再杭电ac(一直wa啊),而用java包中的栈和队列就秒过了,问题尚未找出原因,值得思考啊.不过可以趁此学学这两个类(尽量还是自己动手写的好啊) 栈:java.util 类 Stack<E> Stack 类表示后进先出(LIFO)的对象堆栈.它通过五个操作对类 Vector 进行了扩展 ,允许将向量视为堆栈.它提供了通常的push 和 pop