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. css3中transform的用法

    transform:rotate旋转deg #box1{ -moz-transform:rotate(10deg); -webkit-transform:rotate(10deg); }transfo ...

  2. jQuery使用之(三)处理页面的元素

    对于页面的元素,在DOM编程中可以通过各种查询.修改手段进行管理,非常麻烦.jQuery提供了一整套的方法来处理页面的元素.包括元素的内容.复制.移动和替换等.本节将介绍一些常用的内容. 1.直接获取 ...

  3. java Thread编程(三) 同步的两种不同实现方式

    1,创建需要同步的对象(方式一) package concurrency; public class Bank { private double amount; public Bank(double ...

  4. CSS3媒体查询

    随着响应式设计模型的诞生,Web网站又要发生翻天腹地的改革浪潮,可能有些人会觉得在国内IE6用户居高不下的情况下,这些新的技术还不会广泛的蔓延下去,那你就错了,如今淘宝,凡客,携程等等公司都已经在大胆 ...

  5. 【BZOJ-1965】SHUFFLE 洗牌 快速幂 + 拓展欧几里德

    1965: [Ahoi2005]SHUFFLE 洗牌 Time Limit: 3 Sec  Memory Limit: 64 MBSubmit: 541  Solved: 326[Submit][St ...

  6. POJ2186 Popular Cows

    Description Every cow's dream is to become the most popular cow in the herd. In a herd of N (1 <= ...

  7. html中设置锚点定位的几种常见方法(#号定位)

    在html中设置锚点定位我知道的有几种方法,在此和大家分享一下: 1.使用id定位: <a href="#1F">锚点1</a> <div id=&q ...

  8. Model1模式的学生信息增删改查

    Student.java package entity; public class Student { private int stuid; private String stuname; priva ...

  9. javaIO(二)

    在程序中所有的数据都是以流的方式进行传输或保存的,程序需要数据时要使用输入流读取数据,而当程序需要将一些数据保存起来时,就要使用输出流. 在java.io包中流的操作主要有字节流.字符流两大类,两类都 ...

  10. hihocoder1187 Divisors

    传送门 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Given an integer n, for all integers not larger than n, f ...