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. mysql导入.sql文件

    1. source /home/susie ...../**.sql 2. \. /home/susie/.../**.sql 批量导入.sql文件 首先新建一个main.sql,然后在main.sq ...

  2. C语言运算符的注意问题

    //对于自增和自减运算符的运算规律值得研究,小心被坑.1 #include<stdio.h> int main(void){ ,j=,p,q; p=(i++)+(i++)+(i++); q ...

  3. tomcat 项目部署问题

    我本地Tomcat版本:Apache Tomcat/8.0.3.0 服务器端:Apache Tomcat/6.0.37 JVM都是:1.7.0_40-b43 之前项目运行正常,在我更新了一些模块后,重 ...

  4. Ubuntu14.0.4 64位 ADT 连接手机调试问题

    1:使用 lsusb 命令查看USB 设备 y@y:~$ lsusbBus 001 Device 002: ID 8087:8000 Intel Corp. Bus 001 Device 001: I ...

  5. Course Schedule 解答

    Question There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may ...

  6. 图片旋转+剪裁js插件(兼容各浏览器) « 张鑫旭-鑫空间-鑫生活

    图片旋转+剪裁js插件(兼容各浏览器) « 张鑫旭-鑫空间-鑫生活 图片旋转+剪裁js插件(兼容各浏览器) by zhangxinxu from http://www.zhangxinxu.com 本 ...

  7. Socket 相关的知识

    1.关于PF_INET和AF_INET的区别 在写网络程序的时候,建立TCP socket: sock = socket(PF_INET, SOCK_STREAM, 0);然后在绑定本地地址或连接远程 ...

  8. uva 714 - Copying Books(贪心 最大值最小化 二分)

    题目描写叙述开头一大堆屁话,我还细致看了半天..事实上就最后2句管用.意思就是给出n本书然后要分成k份,每份总页数的最大值要最小.问你分配方案,假设最小值同样情况下有多种分配方案,输出前面份数小的,就 ...

  9. 怎样使用jetty

    一直都听说jetty跟Tomcat一样,是一个web容器.之前做项目的时候,也使用过jetty,只是当时jetty是作为一个插件,跟maven集成使用的.那个时候,因为是第一次使用jetty,感觉je ...

  10. LR实战之Discuz开源论坛——登录场景设计

    以下是根据个人项目经验,对登录场景的设计,如下步骤: 一.打开Controller,添加登录脚本,选择“手动场景”,一般我们项目中经常使用的是“手动场景”类型设计,如图 二.在“设计”部分,设置场景的 ...