Problem 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结束字典的输入 然后输入字符串 如果字符串能够组成字典中的串就输出该串 否则输出NOT A VALID WORD

就是找到字典中与其相同字母构成的字符串。

(找到的字符串如果有很多,要按照字典顺序输出!)

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner; /**
* @author 陈浩翔
* 2016-5-27
*/
public class Main{ public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
String str="";
String chStr="";
Map<String , List<String>> map = new HashMap<String, List<String>>();
while(true){
List<String> list = new ArrayList<String>();
str=sc.next();
if("XXXXXX".equals(str)){
break;
}
char ch[] = str.toCharArray();
Arrays.sort(ch);
chStr=new String(ch); if(map.get(chStr)==null){
list.add(str);
map.put(chStr, list);
}else{
list = map.get(chStr);
list.add(str);
map.put(chStr, list);
}
} while(true){
str=sc.next();
if("XXXXXX".equals(str)){
break;
}
char ch[] = str.toCharArray();
Arrays.sort(ch);
chStr=new String(ch);
List<String> list = map.get(chStr);
if(list==null){
System.out.println("NOT A VALID WORD");
}else{
String strs[] = new String[list.size()];
for(int i=0;i<list.size();i++){
strs[i]=list.get(i);
}
Arrays.sort(strs, new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
return o1.compareTo(o2);
}
});
for(int i=0;i<strs.length;i++){
System.out.println(strs[i]);
}
}
System.out.println("******");
}
}
}
}

HDOJ/HDU 1113 Word Amalgamation(字典顺序~Map)的更多相关文章

  1. HDU 1113 Word Amalgamation (map 容器 + string容器)

    http://acm.hdu.edu.cn/showproblem.php?pid=1113 Problem Description In millions of newspapers across ...

  2. HDOJ.1113 Word Amalgamation(map)

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

  3. hdu 1113 Word Amalgamation

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1113 字符串简单题: stl水过 如下: #include<algorithm> #inc ...

  4. hdu - 1113 Word Amalgamation (stl)

    http://acm.hdu.edu.cn/showproblem.php?pid=1113 给定一个字典,然后每次输入一个字符串问字典中是否有单词与给定的字符串的所有字母一样(顺序可以打乱),按字典 ...

  5. hdu 1113 Word Amalgamation 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1113 题意:输入一个字典,然后再输入若干单词(每行中,1 <= 单词数 <= 100,并且 ...

  6. hdu Word Amalgamation(map)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1113 找单词 #include <iostream> #include <strin ...

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

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

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

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

  9. poj 1318 Word Amalgamation

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

随机推荐

  1. OpenCV(5)-图像掩码操作(卷积)-锐化

    锐化概念 图像平滑过程是去除噪声的过程.图像的主要能量在低频部分,而噪声主要集中在高频部分.图像的边缘信息主要也在高频部分,在平滑处理后,将会丢不部分边缘信息.因此需要使用锐化技术来增强边缘. 平滑处 ...

  2. bzoj1485:[HNOI2009]有趣的数列

    思路:首先限制数很多,逐步来考虑,限制一很容易满足,考虑限制二,也就是让奇数位和偶数位上的数递增,限制三就是让奇数位上的数小于奇数位加一对应的偶数位上的数,那么我们可以把形成序列的过程看成加数的过程, ...

  3. bzoj3571: [Hnoi2014]画框 最小乘积匹配+最小乘积XX总结,

    思路大概同bzoj2395(传送门:http://www.cnblogs.com/DUXT/p/5739864.html),还是将每一种匹配方案的Σai看成x,Σbi看成y,然后将每种方案转化为平面上 ...

  4. XCOPY: Access denied

    用 XCOPY 拷贝文件,出现 “Access denied” 提示信息. 原因: 在如上拷贝的目标路径下,存在 ReadMe.txt, 并且是 只读 文件,这种情况下,需要增加一个 拷贝选项: /R ...

  5. 深入理解Python中的生成器

    生成器(generator)概念 生成器不会把结果保存在一个系列中,而是保存生成器的状态,在每次进行迭代时返回一个值,直到遇到StopIteration异常结束. 生成器语法 生成器表达式: 通列表解 ...

  6. IE 动态绑定click事件

    //必须先清除原有的事件 $(dom).attr("onclick", ""); //再重新绑定新的事件 $(dom).bind("click&quo ...

  7. php checkbox复选框值的获取与checkbox默认值输出方法

    php获取 checkbox复选框值的方法,checkbox在php读取值时要用数组形式哦,我们读取这些值用php post获取是以一个array形式哦. php获取 checkbox复选框值的方法 ...

  8. PHP输出图片文件,实现浏览器缓存机制

    $ETag = '"'.md5($file).'"'; if(env('HTTP_IF_NONE_MATCH') === $ETag){ header ( 'ETag: '.$ET ...

  9. JavaBean的使用

    JavaBean主要用于实现一些业务逻辑或封装一些业务对象 通常将JavaBean中的属性设置为私有的(private),但需要为其提供公共的(public)访问方法,也就是所说的getXXX()方法 ...

  10. Linux使用问答

    1.ubuntu 查看安装的软件包? 在终端输入 sudo dpkg -l http://vardesa.blog.hexun.com/58593247_d.html 其他:http://qiuye. ...