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. 利用angular给节点添加样式

    <!DOCTYPE html> <html lang="en" ng-app="myapp"> <head> <met ...

  2. 大数据平台搭建-zookeeper集群的搭建

    本系列文章主要阐述大数据计算平台相关框架的搭建,包括如下内容: 基础环境安装 zookeeper集群的搭建 kafka集群的搭建 hadoop/hbase集群的搭建 spark集群的搭建 flink集 ...

  3. Jexus部署.Net Core项目

    Jexus Jexus 即 Jexus Web Server,简称JWS,是Linux平台上 的一款ASP.NET WEB服务器.它是 Linux.Unix.FreeBSD 等非Windows系统架设 ...

  4. Linux命令 用户管理命令

    groupadd [功能说明] 新建用户组 [语法格式] Groupadd[-f][-r][-g<GID><-o>][组名] [选项参数] 参数 说明 -f 建立已存在的组,强 ...

  5. libpng处理png图片(二)

    一,实现效果:图片剪切, 图片拼接                      ------------------切割后------------------>                  ...

  6. 玩转UITableView系列(一)--- 解耦封装、简化代码、适者生存!

    UITableView这个iOS开发中永远绕不开的UIView,那么就不可避免的要在多个页面多种场景下反复摩擦UITableView,就算是刚跳进火坑不久的iOS Developer也知道实现UITa ...

  7. jQuery实现按Enter键触发事件

    <!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8& ...

  8. phpstrom识别phalcon框架模板文件的配置

  9. textarea禁止拖拽

    <textarea style="resize:none;" ></textarea>'

  10. 【Android Developers Training】 29. 从Activity获得结果

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