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. 01_JavaMail_01_邮件服务器简述

    [收发邮件简单流程] 过程大致是: 发邮件时从客户端发邮件发送到邮件服务器,收邮件就是把邮件服务器的邮件下载到客户端. [邮件协议] * SMTP:(Simple Mail Transfer Prot ...

  2. 专题一、ArrayList增删操作技术细节详解

    一.索引检查 1)在指定位置插入元素时,第一步都需要检查输入的指定位置是否合法 public void add(int index, E element){    rangeCheckForAdd(i ...

  3. .NET MVC 依赖注入 来龙去脉

    找了很久,找到一篇好文章,细读很有收获: 点击打开链接http://www.codeproject.com/Articles/560798/ASP-NET-MVC-Controller-Depende ...

  4. struts2请求过程源码分析(转)

    Struts2是Struts社区和WebWork社区的共同成果,我们甚至 可以说,Struts2是WebWork的升级版,他采用的正是WebWork的核心,所以,Struts2并不是一个不成熟的产品, ...

  5. cenots 下的 lamp(备份与恢复)

    用 putty连接数据库: mysql -uroot -p密码 create database yourdb DEFAULT CHARACTER SET utf8 COLLATE utf8_chine ...

  6. 解决IE6下不支持 png24的透明图片问题

    常用的两种解决方案: 第一:使用IE滤镜解决 关键代码: css代码  _background:none;_filter:progid:DXImageTransform.Microsoft.Alpha ...

  7. PHP优化小结

    1.echo 比 print 快,并且使用echo的多重参数(指用逗号而不是句点)代替字符串连接,比如echo $str1,$str2.如果使用echo $str1.$str2 就会需要 PHP 引擎 ...

  8. sublimeformaya

      网上没有找到这样的插件自己造了一个 https://github.com/jonntd/connectionmaya   附件列表

  9. Mvc学习笔记(4)

    上文我介绍了如何将控制器里的值传递给视图,但是是如何传递的呢?原理是什么? 视图 page.cshtml在编译的时候也会编译成一个类,然而这个类会继承于WebViewPage<object> ...

  10. PS仿制图章

    颜色总不对,和周围不太搭配,这时候把流量调小点,然后用渐变工具.自己实践所得.