博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
杭电1113--Word Amalgamation
阅读量:6071 次
发布时间:2019-06-20

本文共 3268 字,大约阅读时间需要 10 分钟。

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
 

 

Recommend
Eddy   |   We have carefully selected several similar problems for you:            
<1>输入几个字符串,(按字典序排好)→ 用作字典;
<2>输入无序单词,查找;
<3>输出;
1 #include 
2 #include
3 #include
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 //else51 //printf("NOT A VALID WORD\n");52 }53 if(flag==0)54 printf("NOT A VALID WORD\n");55 /*else56 {57 sort(ac,ac+flag,cpm);58 for(i=0; i

 

 

转载于:https://www.cnblogs.com/soTired/p/4676641.html

你可能感兴趣的文章
js执行本地exe文件的3种方法
查看>>
理解B树索引
查看>>
vi编辑器的命令集合
查看>>
Mysql利用binlog恢复数据
查看>>
解决 Windows启动时要求验证
查看>>
我的友情链接
查看>>
用yum安装mariadb
查看>>
一点IT"边缘化"的人的思考
查看>>
Gallery循环滑动
查看>>
Sql与C#中日期格式转换总结
查看>>
iOS开发流程总结
查看>>
hadoop datanode 启动出错
查看>>
js颜色拾取器
查看>>
IDEA使用(1)intellIJ idea 配置 svn
查看>>
Thread Safety in Java(java中的线程安全)
查看>>
WPF 降低.net framework到4.0
查看>>
数据管理DMS 全量SQL诊断:你的SQL是健康的蓝色,还是危险的红色?
查看>>
搭建一个通用的脚手架
查看>>
开年巨制!千人千面回放技术让你“看到”Flutter用户侧问题
查看>>
开源磁盘加密软件VeraCrypt教程
查看>>