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

  1. tarp
  2. given
  3. score
  4. refund
  5. only
  6. trap
  7. work
  8. earn
  9. course
  10. pepper
  11. part
  12. XXXXXX
  13. resco
  14. nfudre
  15. aptr
  16. sett
  17. oresuc
  18. XXXXXX

Sample Output

  1. score
  2. ******
  3. refund
  4. ******
  5. part
  6. tarp
  7. trap
  8. ******
  9. NOT A VALID WORD
  10. ******
  11. course
  12. ******

Attention:对若干个字符串进行字典排序,应用结构体数组储存字符串(二维数组会报错),以用函数 sort 进行排序。

Code:

  1. #include <iostream>
  2. #include <algorithm>
  3. #include <stdio.h>
  4. #include <cstdlib>
  5. #include <cstring>
  6. #include <cmath>
  7. #include <ctime>
  8. #include <ctype.h>
  9.  
  10. using namespace std;
  11.  
  12. char wd[][],wd_sort[][];
  13.  
  14. struct w
  15. {
  16. char res[];
  17. }wd_rs[];
  18.  
  19. bool cmp(struct w a,struct w b)
  20. {
  21. return strcmp(a.res,b.res)<;
  22. }
  23. int main()
  24. {
  25. char wt[];
  26. int len=;
  27. while(scanf("%s",wt)&&strcmp(wt,"XXXXXX"))
  28. {
  29. strcpy(wd[len],wt);
  30. strcpy(wd_sort[len],wd[len]);
  31. len++;
  32. }
  33.  
  34. int k=len;
  35. while(k--)
  36. {
  37. sort(wd_sort[k],wd_sort[k]+strlen(wd_sort[k]));
  38. }
  39.  
  40. char w[];
  41. while(scanf("%s",w)&&strcmp(w,"XXXXXX"))
  42. {
  43. sort(w,w+strlen(w));
  44.  
  45. int flag=,z=;
  46. k=len;
  47. for(int i=;i<=k;i++)
  48. {
  49. if(strcmp(wd_sort[i],w)==)
  50. {
  51. strcpy(wd_rs[z++].res,wd[i]);
  52. flag=;
  53. }
  54. }
  55. if(!flag)
  56. printf("NOT A VALID WORD\n");
  57. else
  58. {
  59. sort(wd_rs,wd_rs+z,cmp);
  60. for(int i=;i<z;i++)
  61. printf("%s\n",wd_rs[i].res);
  62. }
  63. printf("******\n");
  64. }
  65.  
  66. return ;
  67. }

HDU1113 Word Amalgamation的更多相关文章

  1. hdu1113 Word Amalgamation(详解--map和string的运用)

    版权声明:本文为博主原创文章.未经博主同意不得转载. vasttian https://blog.csdn.net/u012860063/article/details/35338617 转载请注明出 ...

  2. Word Amalgamation(枚举 + 排序)

    Word Amalgamation Time Limit: 1 Sec  Memory Limit: 64 MB Submit: 373  Solved: 247 Description In mil ...

  3. hdu-----(1113)Word Amalgamation(字符串排序)

    Word Amalgamation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  4. Word Amalgamation(hdoj1113)

    Word Amalgamation Problem Description In millions of newspapers across the United States there is a ...

  5. HDOJ.1113 Word Amalgamation(map)

    Word Amalgamation 点我挑战题目 点我一起学习STL-MAP 题意分析 给出字典.之后给出一系列======乱序======单词,要求你查字典,如过这个乱序单词对用有多个有序单词可以输 ...

  6. poj1318 Word Amalgamation 字符串排序(qsort)

    Word Amalgamation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9794   Accepted: 4701 ...

  7. poj 1318 Word Amalgamation

    Word Amalgamation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9968   Accepted: 4774 ...

  8. Uva 642 - Word Amalgamation sort qsort

     Word Amalgamation  In millions of newspapers across the United States there is a word game called J ...

  9. hdu 1113 Word Amalgamation 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1113 题意:输入一个字典,然后再输入若干单词(每行中,1 <= 单词数 <= 100,并且 ...

随机推荐

  1. Mac 上Python多版本切换

    Mac上自带了Python2.x的版本,有时需要使用Python3.x版本做开发,但不能删了Python2.x,可能引起系统不稳定,那么就需要安装多个版本的Python. 1.安装Python3.x版 ...

  2. mysql关闭/启用外键约束

    1.有时为了导入数据方便,需要临时关闭外键约束mysql>SET FOREIGN_KEY_CHECKS=0; 2.打开外键约束mysql>SET FOREIGN_KEY_CHECKS=1; ...

  3. flask 扩展之 -- flask-pagedown

    支持 Markdown 语法, 并添加 富文本文章的预览功能. 使用到的包列表: PageDown : 使用 JavaScript 实现的客户端 Markdown 到 HTML 的转换程序. Flas ...

  4. PHPCMS V9 导航栏当前栏目高亮

    实际上这个东西可有可无,很多站点看似导航栏当鼠标指向后都会变化等高亮处理,一般都比较醒目,但是实质点击过去后,都还是只是刚才的样式,因为这些站点的导航栏都没有对当前选中栏目做CSS的指定变化处理. 该 ...

  5. java架构师负载均衡、高并发、nginx优化、tomcat集群、异步性能优化、Dubbo分布式、Redis持久化、ActiveMQ中间件、Netty互联网、spring大型分布式项目实战视频教程百度网盘

    15套Java架构师详情 * { font-family: "Microsoft YaHei" !important } h1 { background-color: #006; ...

  6. vue1与vue2的路由 以及vue2项目大概了解

    vue1的路由 1.设置根组件  Vue.extend() 2.设置局部组件  Vue.extend({template:"/home"}) 3.实例化路由   var route ...

  7. 【数据结构与算法】一致性Hash算法及Java实践

    追求极致才能突破极限 一.案例背景 1.1 系统简介 首先看一下系统架构,方便解释: 页面给用户展示的功能就是,可以查看任何一台机器的某些属性(以下简称系统信息). 消息流程是,页面发起请求查看指定机 ...

  8. c# 读写文件时文件正由另一进程使用,因此该进程无法访问该文件

    c# 读写文件时文件正由另一进程使用,因此该进程无法访问该文件,在IO处理上遇到了无法操作的问题. 文件"D:\log.txt"正由另一进程使用,因此该进程无法访问该文件. log ...

  9. 【LeetCode】87. Scramble String

    题目: Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty subs ...

  10. 【Android Developers Training】 56. 更效率地加载大图片

    注:本文翻译自Google官方的Android Developers Training文档,译者技术一般,由于喜爱安卓而产生了翻译的念头,纯属个人兴趣爱好. 原文链接:http://developer ...