前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >hdu-----(1113)Word Amalgamation(字符串排序)

hdu-----(1113)Word Amalgamation(字符串排序)

作者头像
Gxjun
发布2018-03-22 14:16:57
6260
发布2018-03-22 14:16:57
举报
文章被收录于专栏:ml

Word Amalgamation

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2586    Accepted Submission(s): 1246

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 ******

Source

Mid-Central USA 1998

代码:

代码语言:javascript
复制
 1 #include<iostream>
 2 #include<algorithm>
 3 using namespace std;
 4 struct node
 5 {
 6     char old[8];
 7     char ne[8];
 8     bool operator <(const node &a)const{
 9        if(strcmp(old,a.old)<0)    return 1;
10      return 0;
11     }
12 }str[105];
13 int main(){
14     int i=0;
15     //freopen("test.in","r",stdin);
16     while(scanf("%s",&str[i].old)&&str[i].old[0]!='X'){
17         strcpy(str[i].ne,str[i].old);
18         sort(str[i].ne,str[i].ne+strlen(str[i].ne));
19         i++;
20     }
21     int n=i;
22     sort(str,str+n);
23     char ss[8];
24     while(scanf("%s",ss)&&ss[0]!='X'){
25        sort(ss,ss+strlen(ss));
26         int cnt=0;
27        for(int i=0;i<n;i++){
28            if(strcmp(ss,str[i].ne)==0){
29           printf("%s\n",str[i].old);
30              cnt++;
31            }
32        }
33        if(!cnt) puts("NOT A VALID WORD");
34        puts("******");
35     }
36  return 0;
37 }
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2014-08-20 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Word Amalgamation
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档