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
******

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

Code:

#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <ctype.h> using namespace std; char wd[][],wd_sort[][]; struct w
{
char res[];
}wd_rs[]; bool cmp(struct w a,struct w b)
{
return strcmp(a.res,b.res)<;
}
int main()
{
char wt[];
int len=;
while(scanf("%s",wt)&&strcmp(wt,"XXXXXX"))
{
strcpy(wd[len],wt);
strcpy(wd_sort[len],wd[len]);
len++;
} int k=len;
while(k--)
{
sort(wd_sort[k],wd_sort[k]+strlen(wd_sort[k]));
} char w[];
while(scanf("%s",w)&&strcmp(w,"XXXXXX"))
{
sort(w,w+strlen(w)); int flag=,z=;
k=len;
for(int i=;i<=k;i++)
{
if(strcmp(wd_sort[i],w)==)
{
strcpy(wd_rs[z++].res,wd[i]);
flag=;
}
}
if(!flag)
printf("NOT A VALID WORD\n");
else
{
sort(wd_rs,wd_rs+z,cmp);
for(int i=;i<z;i++)
printf("%s\n",wd_rs[i].res);
}
printf("******\n");
} return ;
}

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. 处理jQuery append加入的元素 绑定事件无效的方法

    通过jquery append(或者before.after,一样)新添加进网页的元素,常用的事件不能触发,比如:append了id 为 abc 的元素,那么 $(#abc).click(functi ...

  2. js___原生js轮播

    原生js轮播 作为一名前端工程师,手写轮播图应该是最基本掌握的技能,以下是我自己原生js写的轮播,欢迎指点批评: 首先css代码 a{text-decoration:none;color:#3DBBF ...

  3. Python模块之ConfigParser - 读写配置文件

    Python 标准库的 ConfigParser 模块提供一套 API 来读取和操作配置文件. 配置文件的格式 a) 配置文件中包含一个或多个 section, 每个 section 有自己的 opt ...

  4. v9手机版文章内容不显示

    方法一: 打开PHPCMS v9的/phpcms/templates/default/wap/show.html页面, 将网页中的{$content}替换为:{$rs['content']} 这样wa ...

  5. 关于MATLAB处理大数据坐标文件2017529

    今天我们离成功又近了一步,因为又失败了两次 第一次使用了所有特征,理由:前天的特征使用的是取单个特征测试超过85分的特征,结果出现过拟合现象. 本次使用所有特征是为了和昨天的结果作比较. 结果稍好:比 ...

  6. java 单链表的实现

    package liaobiao;//链表测试public class Node { private int value; private Node next; //存放下一个节点的指针 //构造方法 ...

  7. jquery元素是否可见(隐藏)

    var temp1=$(".view_hidden").is(":visible");//是否可见 var temp2=$(".elem_id&quo ...

  8. JS组件系列——自己动手扩展BootstrapTable的 冻结列 功能:彻底解决高度问题

    前言:一年前,博主分享过一篇关于bootstrapTable组件冻结列的解决方案  JS组件系列——Bootstrap Table 冻结列功能IE浏览器兼容性问题解决方案 ,通过该篇,确实可以实现bo ...

  9. [leetcode-582-Kill Process]

    Given n processes, each process has a unique PID (process id) and its PPID (parent process id). Each ...

  10. Idea调试显示切换数据源的设置

    使用IDEA调试时,如果遇到相同方法会在编辑器上提示切换到哪个项目,因为手滑点了Disable,所以导致后来就不提示了,记录下设置方法.