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

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
****** 题意:用XXXXXX表示文本输入部分结束和查询部分结束;如果如果查询的一个单词和输入的单词字母组成一样;输出文本部分所用符合的单词;每查询一次输出*******分隔 题解:一个单词不管怎么排列,经过排序之后的形式一定是一样的,用排序之后的单词作为键值,用map匹配
#include<iostream>
#include<algorithm>
#include<string.h>
#include<string>
#include<math.h>
#include<map>
#include<set>
#define ll long long
using namespace std;
map<string,string>m;
string s,ss;
int n;
int main()
{
int flag=;
while(flag!=)
{
cin>>s;
if(s[]=='X')
{
flag++;
continue;
}
if(flag==)
{
ss=s;
sort(ss.begin(),ss.end());
m[s]=ss; }
if(flag==)
{
int flag2=;
sort(s.begin(),s.end());
map<string,string>::iterator it;
for(it=m.begin();it!=m.end();it++)
{
if(it->second==s)
{
flag2=;
cout<<it->first<<endl;
}
}
if(flag2==)
cout<<"NOT A VALID WORD"<<endl;
cout<<"******"<<endl;
}
} return ; }

poj 1318 Word Amalgamation的更多相关文章

  1. Word Amalgamation(枚举 + 排序)

    Word Amalgamation Time Limit: 1 Sec  Memory Limit: 64 MB Submit: 373  Solved: 247 Description In mil ...

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

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

  3. Word Amalgamation(hdoj1113)

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

  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. poj1318 Word Amalgamation 字符串排序(qsort)

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

  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. poj 1318

    http://poj.org/problem?id=1318 这个题目还是比较水的,不过也可以提升你对字符串的熟悉度以及对一些排序函数和字符函数的使用. 大概的题意就是给你一个字典,这个字典有一些单词 ...

  9. Word Amalgamation

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

随机推荐

  1. HTTP协议中常用相应的状态码总结

    HTTP协议与我们的生活息息相关,尤其对于我们后端开发人员,工作之余我整理了一些HTTP协议响应的一些常见的状态码,希望能帮助大家 HTTP状态码列表 消息(1字头)服务器收到请求,需要请求者继续执行 ...

  2. Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)E(多重集维护)

    #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;long long ans[1000007]; ...

  3. Java - 使用hibernate配置文件 + JPA annotation注解操作数据库

    本程序运行环境:IDEA. 实际上我对hiberbate与注解的关系还不是太清晰.据我所知注解都是Java JPA的,那么我的理解是:hibernate就应该只是通过这些JPA标识及hibernate ...

  4. 个人相关API - 行驶方向判断函数

    calculateDrivingDirection(newCoordinates,oldCoordinates){ let o = { direction: '', deviation:null, i ...

  5. A way to find out how activity for mssql and oracle

    Dear buddy, Have you confuse that how activity about my databases, if we conside it by using backup ...

  6. 使用gitthub 创建项目搭建博客

    最近在学Andrew Ng 的机器学习,做了上买那个的练习题和变成作业,想着把自己做的编程作业放到GitHub,方便讨论,虽然之前注册了GitHub,但这两年整天在毕设方向的事,做的身心俱疲,再加上自 ...

  7. 「HNOI2016」大数

    题目描述 给定一个质数\(p\)和一个数字序列,每次询问一段区间\([l,r]\), 求出该序列区间\([l,r]\)内的所有子串,满足该子串所形成的数是\(p\)的倍数(样例的解释也挺直观的) 基本 ...

  8. mybatis关键查询

    一.一对一关联 1.1.提出需求 根据班级id查询班级信息(带老师的信息) 1.2.创建表和数据 创建一张教师表和班级表,这里我们假设一个老师只负责教一个班,那么老师和班级之间的关系就是一种一对一的关 ...

  9. Python 类型转换指南

    一.int型 支持转换为 int 类型的,仅有 float.str.bytes,其他类型均不支持. 1.float -> int会去掉小数点及后面的数值,仅保留整数部分. 2.str -> ...

  10. 学习进度-16 python爬虫

    爬虫是一个程序,这个程序的目的就是为了抓取万维网信息资源,比如你日常使用的谷歌等搜索引擎,搜索结果就全都依赖爬虫来定时获取 从百度可以看出来 爬虫与python关系很紧密, 爬虫的目标对象也很丰富,不 ...