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. Unity 安卓下DLL热更新一(核心思想)

    大家都知道一谈起热更新的话首选是Ulua这个插件, 其实Unity可以使用dll热更新的,如果你实在不想用Lua来编写逻辑,0.0请下看Dll+AssetBundle如何实现热更新的.让你看完这个文章 ...

  2. eclipse配置maven + 创建maven项目

        登录|注册     努力+坚持,而且还很年轻   目录(?)[+] 在现实的企业中,以低成本.高效率.高质量的完成项目,不仅仅需要技术大牛,企业更加需要管理大牛,管理者只懂技术是远远不够的.当 ...

  3. 虚拟机IOS开发环境搭建教程

    来源:http://www.cnblogs.com/xiaoyaoju/archive/2013/05/21/3091171.html 安装条件: 硬件:一台拥有支持虚拟技术的64位双核处理器和2GB ...

  4. LDA-线性判别分析(四)

    本来是要调研 Latent Dirichlet Allocation 的那个 LDA 的, 没想到查到很多关于 Linear Discriminant Analysis 这个 LDA 的资料.初步看了 ...

  5. Oracle中drop user和drop user cascade的区别

    drop user : 仅仅是删除用户,drop user username cascade :会删除此用户名下的所有表和视图. userSpecify the user to be dropped. ...

  6. [HeadFirst-HTMLCSS学习笔记][第十二章HTML5标记]

    考虑HTML结构 HTML5即是把原来<div>换成一些更特定的元素.能够更明确指示包含什么内容. (页眉,导航,页脚,文章) article nav 导航 header footer t ...

  7. fastclick.js介绍

    原文地址:http://www.uedsc.com/fastclick.html 用途:去掉移动端click事件的300ms的延迟. 延迟为什么存在   …在移动浏览器中,当你点击按钮的单击事件时,将 ...

  8. BOM 窗体相关属性以及页面可见区域的获取方式

    1 在IE Safari Oper Chrome 都提供了screenLeft和screenTop属性: screenLeft : 相对于屏幕左边的距离 screenTop : 相对于屏幕上边的距离 ...

  9. Entity Framework 6.1-Code First【转】

      Entity Framework 6.1-Code First 分类: Entity Framework 2014-04-21 14:56 2034人阅读 评论(0) 收藏 举报 entityen ...

  10. 1207--ATM自动取款机的实现

    #include <stdio.h> #include <stdlib.h> #include <stdbool.h> //提示用户操作 void alert(ch ...