Word Amalgamation

Time Limit: 1 Sec  Memory Limit: 64 MB Submit: 373  Solved: 247

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

HINT

 #include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
char a[][] ;
char b[][] ; void Sort (int n)
{
for (int i = ; i < n; i++) {
if (strcmp (a[i] , a[i - ]) < ) {
char ans[] ;
strcpy (ans , a[i] ) ;
int j ;
for (j = i - ; j >= && strcmp (ans , a[j]) < ; j--) {
strcpy (a[j + ] , a[j] ) ;
}
strcpy (a[j + ] , ans ) ;
}
}
} int main ()
{
//freopen ("a.txt" , "r" , stdin ) ;
int n = , s ;
do {
gets (a[n++]) ;
} while (strcmp (a[n - ] , "XXXXXX") != ) ;
n-- ;
Sort (n) ;
int k = ;
do {
gets (b[k++]) ;
} while (strcmp (b[k - ] , "XXXXXX") != ) ;
k-- ;
for (int i = ; i < k ; i++) {
bool flag = ;
for (int j = ; j < n ; j++) {
int l1 , l2 ;
char s1[] ;
char s2[] ;
strcpy (s1 , b[i]) ; l1 = strlen (s1) ; //puts (s1) ;
strcpy (s2 , a[j]) ; l2 = strlen (s2) ; //puts (s2) ;
if (l1 != l2)
continue ;
sort (s1 , s1 + l1 ) ; //puts (s1) ;
sort (s2 , s2 + l2 ) ; //puts (s2) ;
for (s = ; s < l1 ; s++) {
if (s1[s] != s2[s])
break ;
}
if (s == l1) {
printf ("%s\n" , a[j]) ;
flag = ;
}
}
if (!flag) {
puts ("NOT A VALID WORD") ;
puts ("******") ;
}
else {
puts ("******") ;
}
}
return ;
}

Word Amalgamation(枚举 + 排序)的更多相关文章

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

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

  2. ZOJ1181 Word Amalgamation 字符串 排序查找

    传送门:ZOJ1181  思路:自身排序来判断两个字符串拥有相同的字符.   #include<cstdio> #include<cstdlib> #include<io ...

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

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

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

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

  5. HDOJ.1113 Word Amalgamation(map)

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

  6. poj 1318 Word Amalgamation

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

  7. Uva 642 - Word Amalgamation sort qsort

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

  8. OpenMP之枚举排序

    // EnumSort.cpp : 定义控制台应用程序的入口点. //枚举排序 /* 枚举排序(Enumeration Sort)是一种最简单的排序算法,通常也称为秩排序(Rank Sort). 该算 ...

  9. Word Amalgamation(hdoj1113)

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

随机推荐

  1. RF源码阅读(碎片纪录)-Python积木之contextlib

    参考页面: http://docs.python.org/2/library/contextlib.html contextlib是为了配合with语句来使用的.使用起来更加简洁.本来想写一下,这位同 ...

  2. 学习笔记——Maven实战(三)多模块项目的POM重构

    重复,还是重复 程序员应该有狗一般的嗅觉,要能嗅到重复这一最常见的坏味道,不管重复披着怎样的外衣,一旦发现,都应该毫不留情地彻底地将其干掉.不要因为POM不是产品代码而纵容重复在这里发酵,例如这样一段 ...

  3. wpf键盘记录器

    很简单的一个wpf键盘记录器 这个程序我一样用了全局勾子,之前用的都是winform上运行了,前一段时间 在国外的论坛上逛看到了一个wpf能用的就做了一个小程序记录一下,为了方便大家直关的看我在页面上 ...

  4. cookie的操作

    比如这样如果一个网站上有两个域名的时候,我们需要考虑,两个域名下的cookie. 我们所说的跨域只的就是lesport.com和le.com js的cookie是不能跨域的,为了防止过大. js增加删 ...

  5. 20.C#LINQ基础和简单使用(十一章11.1-11.2)

    终于看到了第11章,之前虽然也有看过,但没有太仔细,在工作中也偶尔会使用,但不明白其中的原理,那现在就来讲讲LINQ,做一做书虫~~ 首先先了解下LINQ的三个要点: LINQ不能把非常复杂的查询表达 ...

  6. iOS开发小技巧--字典和数组的中文输出

    一.在解析json数据的时候,得到的集合对象或者数组对象在用%@打印的时候回出现类似乱码的情况.如图: 在iOS中打印字典或者数组对象,系统会默认调用字典对象和数组对象的descriptionWith ...

  7. hdu4287 字典树

    #include<stdio.h> #include<string.h> #include<stdlib.h> #define maxn 10 struct tri ...

  8. shell--题目

    1.有一个文件,里面有二列,第一列ip地址,第二列是时间,同一个ip可能出现多次,但时间不同. 文件类似下面的样子: 192.168.1.2              13:10 192.127.12 ...

  9. 打印cell的视图层次结构

    #ifdef DEBUG NSLog(@"Cell recursive description:\n\n%@\n\n", [cell performSelector:@select ...

  10. 安装最新版本的ReSharper导致原生全局搜索工具的消失问题

    经过检测,是由于启用了一个插件导致的,禁用即可,如下图: