博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDOJ/HDU 1113 Word Amalgamation(字典顺序~Map)
阅读量:5909 次
发布时间:2019-06-19

本文共 3424 字,大约阅读时间需要 11 分钟。

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******parttarptrap******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
> map = new HashMap
>(); while(true){ List
list = new ArrayList
(); 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
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
() { @Override public int compare(String o1, String o2) { return o1.compareTo(o2); } }); for(int i=0;i

转载地址:http://pstpx.baihongyu.com/

你可能感兴趣的文章
深入了解MyBatis二级缓存
查看>>
Java IO(1)基础知识——字节与字符
查看>>
3.7 su命令 3.8 sudo命令 3.9 限制root远程登录
查看>>
数组 类型 在 存储过程中 使用
查看>>
Vmware Workstation及Centos6.8 的安装
查看>>
Android系统shell中的clear命令实现【转】
查看>>
全网最全的Windows下Anaconda2 / Anaconda3里正确下载安装爬虫框架Scrapy(离线方式和在线方式)(图文详解)...
查看>>
生成字符Banner
查看>>
通过例子理解 k8s 架构 - 每天5分钟玩转 Docker 容器技术(122)
查看>>
[UWP]附加属性2:实现一个Canvas
查看>>
SQLServer 复制中移除和添加发布而不初始化所有项目
查看>>
CXF WebService中传递复杂对象(List、Map、Array)
查看>>
【BIEE】11_根据显示指标展示不同报表
查看>>
Mybatis分页插件PageHelper简单使用
查看>>
Docker基础技术:DeviceMapper
查看>>
hadoop生态系统学习之路(十)MR将结果输出到hbase
查看>>
HDOJ 4455 Substrings 递推+树状数组
查看>>
spark2.1:flatMap的用法
查看>>
leetcode 520. Detect Capital
查看>>
chrome离线包出现的小问题
查看>>