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 ...
随机推荐
- 安卓模拟器"bluestacks"在电脑上的设置.(宽,高)
可以在手机上找到大量英语学习APP. 习惯使用电脑的朋友,可以安装模拟器来使用这些APP. bluestacks 是一款比较好的模拟器. 但其默认的宽,高,却无法在软件中修改. 找到一个比较好的教程来 ...
- 02_使用WebMagic爬虫获取CSDN推荐专家的个人博客信息
本来是想抓取博客园的博客推荐的页面的,但由于一些博客进去的页面格式都不太相同,一时不想花时间去寻找规律,发现CSDN上面的格式较为单一,就决定以CSDN推荐专家的个人博客信息作为爬虫抓取的目标. [首 ...
- Codeforces Round #299 (Div. 1)
Problem A: 实际上对于一段数字假设和为k,每次取较大的m个进行t次减一操作,最多减去的是min(m*t,k). 明白了这个结论就可以直接二分答案了. #include <bits/st ...
- 九度OJ 1435 迷瘴
题目地址:http://ac.jobdu.com/problem.php?pid=1435 题目描述: 通过悬崖的yifenfei,又面临着幽谷的考验—— 幽谷周围瘴气弥漫,静的可怕,隐约可见地上堆满 ...
- IOS 学习日志 2015-3-13
前面几天在看C ,但是没有做笔记,现在在看Objective--C ,开始做笔记,希望每一天都有成长吧 Objective--C 关键字 1 @import 导入 注意<>||" ...
- HTML教程:link标记
开发php语言的网站,<head>里link标签这样:<link href="xmlrpc.php?rsd=1" title="rsd" ty ...
- MySQL数据库添加一个字段
MySQL数据库添加一个字段 1.添加一个字段 alter table tableName add 列名 数据类型; 2.添加一个字段设置默认值 alter table tableName add ...
- ubuntu apt-get
近期重新拿起linux的书看了下,整理了一下linux的命令. ubuntu预装了APT和dpkg ,“APT”是 “Advanced Package Tool”的简写,“dpkg ”是“Debian ...
- 操作系统和Python的发展历程
一:操作系统的发展历史: 操作系统:什么是操作系统?我们首先想到的是电脑,,也就是所谓的Windows8,Windows7,或者XP系统和Windows10,当然也包括我们手机的安卓系统或者IPhon ...
- 【python】python的列表表达式或解析式,帅就一个字
>>> list1 = [x**2 for x in range(10)]>>> list1[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]