HDOJ/HDU 1113 Word Amalgamation(字典顺序~Map)
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:
- a dictionary, which consists of at least one and at most 100 words, one per line;
- a line containing XXXXXX, which signals the end of the dictionary;
- one or more scrambled `words’ that you must unscramble, each on a line by itself; and
- 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)的更多相关文章
- HDU 1113 Word Amalgamation (map 容器 + string容器)
http://acm.hdu.edu.cn/showproblem.php?pid=1113 Problem Description In millions of newspapers across ...
- HDOJ.1113 Word Amalgamation(map)
Word Amalgamation 点我挑战题目 点我一起学习STL-MAP 题意分析 给出字典.之后给出一系列======乱序======单词,要求你查字典,如过这个乱序单词对用有多个有序单词可以输 ...
- hdu 1113 Word Amalgamation
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1113 字符串简单题: stl水过 如下: #include<algorithm> #inc ...
- hdu - 1113 Word Amalgamation (stl)
http://acm.hdu.edu.cn/showproblem.php?pid=1113 给定一个字典,然后每次输入一个字符串问字典中是否有单词与给定的字符串的所有字母一样(顺序可以打乱),按字典 ...
- hdu 1113 Word Amalgamation 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1113 题意:输入一个字典,然后再输入若干单词(每行中,1 <= 单词数 <= 100,并且 ...
- hdu Word Amalgamation(map)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1113 找单词 #include <iostream> #include <strin ...
- hdu1113 Word Amalgamation(详解--map和string的运用)
版权声明:本文为博主原创文章.未经博主同意不得转载. vasttian https://blog.csdn.net/u012860063/article/details/35338617 转载请注明出 ...
- poj1318 Word Amalgamation 字符串排序(qsort)
Word Amalgamation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9794 Accepted: 4701 ...
- poj 1318 Word Amalgamation
Word Amalgamation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9968 Accepted: 4774 ...
随机推荐
- itoa : Convert integer to string
Quote from: http://www.cplusplus.com/reference/cstdlib/itoa/ function Required header : <s ...
- 九度OJ 1451 不容易系列之一 -- 动态规划
题目地址:http://ac.jobdu.com/problem.php?pid=1451 题目描述: 大家常常感慨,要做好一件事情真的不容易,确实,失败比成功容易多了! 做好“一件”事情尚且不易,若 ...
- 关于C# Winform 程序开机自动启动
1.程序运行时调用下面方法即可. /// <summary> /// 设置开机自动启用 /// </summary> private void SetAutoStart() { ...
- apache .htaccess 伪静态重定向,防盗链 限制下载...
301全站跳转 RewriteEngine OnRewriteCond %{HTTP_HOST} ^www\.old\.net$ [NC]RewriteRule ^(.*)$ http://www.n ...
- JavaScript语言用10张图
JavaScript 语言基础知识点总结,用图片树形结构说明.包括Windows对象.JavaScriptDOM基本操作.JavaScript变量.JavaScript数据类型.JavaScript运 ...
- 小笔记(一):ajax传递数组及将ajax返回数据赋值
当使用ajax传递数据时,有可能传递多个数据,这是使用以下方法传递数据就会显得数据过多且混杂 $.ajax({ type:'post', url:url, data:{data:data,conten ...
- python 数据运算
算数运算:
- sql性能优化总结(转)
网上看到一篇sql优化的文章,整理了一下,发现很不错,虽然知道其中的部分,但是没有这么全面的总结分析过…… 一. 目的 数据库参数进行优化所获得的性能提升全部加起来只占数据库应用系统性能提升的40 ...
- USB驱动能力有限
笔者用USB接一个单片机最小系统,再从单片机最小系统引出电源线接一个数字电路模块.当后边两部分的功率较大时,就会引起USB电压的下降,甚至到3V左右.电压的下降就会使单片机或者数字电路部分芯片不能正常 ...
- CodeFirst数据库迁移小记
打开“程序包管理器控制台”菜单项一.Enable-Migrations -ContextTypeName Code_First_数据迁移.Models.T_DbContext成功后提示:已在项目“Co ...