Word Amalgamation

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
******
 #include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int cmp(int n,char *p,char *q)
{
sort(p,p+n);
sort(q,q+n);
if(==strcmp(p,q))
return ;
else
return ;
}
int main()
{
char a[][],b[][],c[][],i=,j,count1,count2;
bool flags=;
// freopen("in.txt","r",stdin);
while(gets(a[i]))
{
if(!strcmp(a[i],"XXXXXX"))
break;
else
i++;
}
count1=i,i=;/*个数*/
while(gets(b[i]))
{
if(!strcmp(b[i],"XXXXXX"))
break;
else
i++;
}
count2=i;
for(i=;i<count2;i++)
{
int k=;
int lenb=strlen(b[i]);
char bb[];
strcpy(bb,b[i]);
for(j=;j<count1;j++)
{
int lena=strlen(a[j]);
char aa[];
strcpy(aa,a[j]);
if((lena==lenb)&&cmp(lena,bb,aa))
{
strcpy(c[k],a[j]);
k++;
flags=;
}
}
char uu[];
int p;
for(j=;j<k-;j++)
for(p=j+;p<k;p++)
{
if(strcmp(c[j],c[p])>=)
{
strcpy(uu,c[j]);
strcpy(c[j],c[p]);
strcpy(c[p],uu);
}
}
for(j=;j<k;j++)
cout<<c[j]<<endl;
if(flags)
cout<<"******"<<endl;
else
cout<<"NOT A VALID WORD"<<endl<<"******"<<endl;
flags=;
}
}

Word Amalgamation(hdoj1113)的更多相关文章

  1. HDOJ.1113 Word Amalgamation(map)

    Word Amalgamation 点我挑战题目 点我一起学习STL-MAP 题意分析 给出字典.之后给出一系列======乱序======单词,要求你查字典,如过这个乱序单词对用有多个有序单词可以输 ...

  2. hdu Word Amalgamation(map)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1113 找单词 #include <iostream> #include <strin ...

  3. Java 操作Word书签(二):添加文本、图片、表格到书签内容

    在Java操作Word书签(一)中介绍了给Word中的特定段落或文字添加书签.读取及删除已有书签的方法,本文将继续介绍Java 操作Word书签的方法,即如何给已有的书签添加内容,包括添加文本.图片. ...

  4. hdu1113 Word Amalgamation(详解--map和string的运用)

    版权声明:本文为博主原创文章.未经博主同意不得转载. vasttian https://blog.csdn.net/u012860063/article/details/35338617 转载请注明出 ...

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

    Word Amalgamation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  6. java使用POI操作XWPFDocument 生成Word实战(一)

    注:我使用的word 2016功能简介:(1)使用jsoup解析html得到我用来生成word的文本(这个你们可以忽略)(2)生成word.设置页边距.设置页脚(页码),设置页码(文本) 一.解析ht ...

  7. c# 操作Word总结(车)

    在医疗管理系统中为保存患者的体检和治疗记录,方便以后的医生或其他人查看.当把数据保存到数据库中,需要新建很多的字段,而且操作很繁琐,于是想到网页的信息创建到一个word文本中,在显示的时,可以在线打开 ...

  8. English trip Spoken English & Word List(updating...)

    Word List 词汇 Square  英 [skweə]  美 [skwɛr]  adj. 平方的:正方形的:直角的:正直的. 使成方形:与…一致 vi. 一致:成方形 n. 平方:广场:正方形 ...

  9. 用python解析word文件(三):style

    太长了,我决定还是拆开三篇写.   (一)段落篇(paragraph) (二)表格篇(table) (三)样式篇(style)(本篇) 选你所需即可.下面开始正文. 在前两篇中,我们已经解析出了par ...

随机推荐

  1. Effective Java单元测试TestNG - 就是爱Java

    TestNG是另一种单元测试的framework,与JUnit的类似,这次Mix将使用它来撰写测试程序,大部分所引用的class package都一样,只差在JUnit与TestNG的字样,可以直接用 ...

  2. USB信号是什么类型的? 为什么在D+,D-处要接上拉下拉电阻呢,具体阻值要如何计算

    USB协议要求的,1.5K上拉在D+时表示是全速设备,在D-表示不是全速设备有些方案里面(比如PNX5230)推荐D+/D-接下拉1M的电阻是为了提高数据传输稳定性的 ①  usb有主从设备之分,主设 ...

  3. setAdapter(adapter)空指针nullPointer 解决办法

    setAdapter(adapter)空指针nullPointer 解决办法 (2014-06-13 10:01:23) 转载▼ 标签: 旅游 分类: Android开发 如果setAdapter报空 ...

  4. < IOS > X-code 5.1 x86 - 64 编译问题

    关于xcode 5.1   x86 - 64 编译问题   坐等了N久,终于IOS 7.1 发布了,作为一个果粉,忍不住第一时间升级了.结果用设备测试的时候,出问题了,一直检测不到设备,哈哈,纠结了半 ...

  5. UESTC_Frozen Rose-Heads CDOJ 791

    The winter is coming and all the experts are warning that it will be the coldest one in the last hun ...

  6. poj 1703(带权并查集)

    Find them, Catch them Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 31840   Accepted: ...

  7. [Oracle] Data Guard 系列(5) - 创建逻辑备库

    在创建逻辑备库之前,必须得先创建物理备库,关于如何创建物理备库,请参考<Data Guard 系列(4) - 在不停主库的情况下创建物理备库>. 1. 在物理备库上停止日志应用服务 SYS ...

  8. Python re模块 正则表达式

    1 简介 就其本质而言,正则表达式(或 RE)是一种小型的.高度专业化的编程语言,(在Python中)它内嵌在Python中,并通过 re 模块实现.正则表达式模式被编译成一系列的字节码,然后由用 C ...

  9. iOS 系统架构 && 常用 framework

    整理自互联网,感谢原文作者! 1.iOS基于UNIX系统,因此从系统的稳定性上来说它要比其他操作系统的产品好很多 2.iOS的系统架构分为四层,由上到下一次为:可触摸层(Cocoa Touch lay ...

  10. iOS学习之iOS沙盒(sandbox)机制和文件操作(一)

    1.iOS沙盒机制 iOS应用程序仅仅能在为该改程序创建的文件系统中读取文件,不能够去其他地方訪问,此区域被成为沙盒,所以全部的非代码文件都要保存在此,比如图像,图标,声音,映像,属性列表,文本文件等 ...