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. 魅蓝Note2 在Android Studio 与 Eclipse中无法被检测到

    昨天到手的Note2 结果发现测试不了,一看魅蓝的版本是android 5.1,然后更新的自己的SDK. 最后…… 仍然不能识别到手机. ———————————— 今天在stackoverflow上搜 ...

  2. Unity3D 文字滚动跑马灯效果

    需求 在日常游戏中,文字滚动效果是比较常用的.例如日常游戏顶部的新闻公告,聊天系统的文字滚动,都属于这个范围. 思路 由于使用的地方比较广泛,所以希望能够尽量独立的游戏之外,能够做到随处使用的功能.N ...

  3. Ajax在调用含有SoapHeader的webservice方法

    ·         [WebService(Namespace = "http://tempuri.org/")] ·             [WebServiceBinding ...

  4. windows API 开发飞机订票系统 图形化界面 (三)

    来吧,接下来是各个功能的函数的实现代码. 首先,程序运行时加载读入账户信息和航班信息.接下来就该读取文件了. 我把账户资料和航班信息储存在了.txt文件里 那么问题就来了,挖掘机...额,不对,应该怎 ...

  5. blur效果,模糊效果css

    .blur { -webkit-filter: blur(5px);   -moz-filter: blur(5px);   -o-filter: blur(5px);   -ms-filter: b ...

  6. [设计模式] javascript 之 抽象工厂模式

    抽象工厂模式说明 1. 工厂方法模式的问题: 在工厂方法模式里,创建类都需要通过 工厂类,如果要扩展程序,就必须修改工厂类,这违背了闭包原则,对扩展开放,对修改关闭:对于设计有一定的问题. 2. 如何 ...

  7. java和linux的编码

    最近要使用中科院计算所的关键词工具NLPIR,用java调用,在windows下测试后放到linux下跑,就发现会有乱码. windows下默认是GBK,linux下是utf-8,因此在意料之中(尽管 ...

  8. 小菜鸟学 MQ(三)

    创建程序测试MQ 1,创建生产者 package com.robert; import java.util.Hashtable; import java.util.Map; import javax. ...

  9. 【BZOJ-4407】于神之怒加强版 莫比乌斯反演 + 线性筛

    4407: 于神之怒加强版 Time Limit: 80 Sec  Memory Limit: 512 MBSubmit: 241  Solved: 119[Submit][Status][Discu ...

  10. 【poj2186】 Popular Cows

    http://poj.org/problem?id=2186 (题目链接) 题意 给出一个n个点m条边的有向图,求其中没有出度强连通分量所包含的点有几个 Solution 其实这道题的题解已经在“题意 ...