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
******
 题意:第一个XXXXXX前是一个字典,对于第二个XXXXXX前的单词输出字典,须排序;
代码:
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
char word[105][10];
int cmp(const void *p1,const void *p2){
    return (strcmp((char *)p1,(char *)p2));
}
int Judge(char m[],char n[]){int t1,t2;
    t1=strlen(m);t2=strlen(n);
    sort(m,m+t1);sort(n,n+t2);
    if(strcmp(n,m)==0)return 1;
    else return 0;
}
int main(){int i,temp;char s[10],t[10],p[10];
    for(i=0;scanf("%s",word[i]),strcmp(word[i],"XXXXXX");++i);
/*for(int z=0;z<=i;++z){
        for(int j=z;j<=i;j++){
            if(strcmp(word[z],word[j])>0)strcpy(p,word[z]),strcpy(word[z],word[j]),strcpy(word[j],p);
        }
    }*///冒泡排序;
     qsort(word,i,sizeof(word[0]),cmp);//qsort   poj上一直wa,杭电过了;运行时间和内存都特别大。。。。。
    while(scanf("%s",s),strcmp(s,"XXXXXX")){temp=0;
        for(int j=0;j<=i;j++){strcpy(t,word[j]);
            if(Judge(s,t))temp=1,printf("%s\n",word[j]);
        }
        if(!temp)printf("NOT A VALID WORD\n");
        printf("******\n");
    }
    return 0;
}

Word Amalgamation的更多相关文章

  1. Word Amalgamation(枚举 + 排序)

    Word Amalgamation Time Limit: 1 Sec  Memory Limit: 64 MB Submit: 373  Solved: 247 Description In mil ...

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

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

  3. Word Amalgamation(hdoj1113)

    Word Amalgamation Problem Description In millions of newspapers across the United States there is a ...

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

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

  5. HDOJ.1113 Word Amalgamation(map)

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

  6. poj1318 Word Amalgamation 字符串排序(qsort)

    Word Amalgamation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9794   Accepted: 4701 ...

  7. poj 1318 Word Amalgamation

    Word Amalgamation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9968   Accepted: 4774 ...

  8. Uva 642 - Word Amalgamation sort qsort

     Word Amalgamation  In millions of newspapers across the United States there is a word game called J ...

  9. hdu 1113 Word Amalgamation 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1113 题意:输入一个字典,然后再输入若干单词(每行中,1 <= 单词数 <= 100,并且 ...

  10. hdu 1113 Word Amalgamation

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1113 字符串简单题: stl水过 如下: #include<algorithm> #inc ...

随机推荐

  1. PHP foreach()跳出本次或当前循环与终止循环方法

    PHPforeach()跳出本次或当前循环与终止循环方法 PHP中用foreach()循环中,想要在循环的时候,当满足某个条件时,想 $arr = array('a','b','c','d','e') ...

  2. 划分树 poj2104 hdu5249

    KPI Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submis ...

  3. boost::asio 的同、异步方式

    转自:http://blog.csdn.net/zhuky/archive/2010/03/10/5364574.aspx Boost.Asio是一个跨平台的网络及底层IO的C++编程库,它使用现代C ...

  4. 国内外移动端web适配屏幕方案

    基础知识点 设备像素:设备像素又称物理像素(physical pixel),设备能控制显示的最小单位,我们可以把这些像素看作成显示器上一个个的点. iPhone5的物理像素是640X1136. PS: ...

  5. CSS3 target伪类简介

    CSS3 target伪类是众多实用的CSS3特性中的一个.它用来匹配文档(页面)的URI中某个标志符的目标元素.具体来说,URI中的标志符通常会包含一个”#”字符,然后后面带有一个标志符名称,比如# ...

  6. NFinal学习笔记 02—NFinalBuild

    在学习NFinal的过程中发现在线.net编译器Web版—— NFinalBuild 什么是NFinalBuild呢?它就是帮助我们简单又快速的更新我们网站的一种编译器,我们不用再只为了更新.net网 ...

  7. WCF入门教程系列一

    一.概述 Windows Communication Foundation(WCF)是由微软发展的一组数据通信的应用程序开发接口,可以翻译为Windows通讯接口,它是.NET框架的一部分.由 .NE ...

  8. 并行开发学习随笔1——plinq并行

    这两天在看园友的文章 <8天玩转并行开发——第三天 plinq的使用> 对里面的第一个实例亲手实践了一下,发现了一点有意思的事情. 测试环境:.net 4.5 64位(如果是32位的,测试 ...

  9. build opencv with python support

    cmake -DPYTHON_LIBRARY=/opt/anaconda/lib/libpython2.7.so -DPYTHON_INCLUDE_DIR=/opt/anaconda/include/ ...

  10. [ZooKeeper研究]二 ZooKeeper协议介绍

    前面介绍了ZooKeeper的基本知识,这一节我们介绍一下ZooKeeper使用的协议.只有了解了ZooKeeper的协议,才能更好得理解ZooKeeper源代码的实现.ZooKeeper使用的是Za ...