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. cocos2dx 编写shader 遇到 溢出问题

    在 编程语言中,不论什么 数据类型 都有 各种 的 局限,无法 表示 现实世界中的 不论什么 情况. 比如 int ,char 会 溢出,float 会 有 溢出 以及 精度 不准确的 情况. 所以 ...

  2. [Elasticsearch] 部分匹配 (三) - 查询期间的即时搜索

    本章翻译自Elasticsearch官方指南的Partial Matching一章. 查询期间的即时搜索(Query-time Search-as-you-type) 如今让我们来看看前缀匹配可以怎样 ...

  3. 期望dp-hdu-4336-Card Collector

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4336 题目大意: 有n种卡片,每包中至多有一种卡片,概率分别为p1,p2,...pn,可能有的没有卡 ...

  4. [SASS] Make a responsive arrow box

    Check the page:http://www.cssarrowplease.com/ In HTML: {{type}} is tow way binding in Angular, three ...

  5. HLJOJ1015(多源最短路径失真)

    意甲冠军:n,m,k,有着n村.有着k路,每个村都有一个电话亭,现在,我们要建立在村中心展台,快递每一个需要同村的中心村,然后返回报告(有向图),有着m电话,假设村配置的手机,那么你并不需要报告.最低 ...

  6. ORA-25154/ORA-01748

    SQL> select oi.order_id,product_id,order_date from order_items oi join orders o using(order_id) w ...

  7. table-cell完成左侧定宽,右侧定宽及左右定宽等布局

    使用table-cell完成以下几种布局(ie8及以上兼容) 1.左侧定宽-右侧自适应 .left{ width: 300px; height: 500px; border: 1px solid; f ...

  8. Javascript中使用replace()方法+正则表达式替换掉所有字符

    Js中的replace方法,只能替换掉第一次匹配到的字符,   而我们经常需要替换一个字符串中所有的匹配字符,这时候可以用正则表达式: str.replace(/a/g,"b"); ...

  9. 数组,集合 转成DataTable 方法

    public static DataTable ToDataTable(IList p_List) { DataTable _DataTable = new DataTable(); if (p_Li ...

  10. c# 运算符 ?、??、?:

    用途:简化代码 说明: ? 是可空类型和运算符 int a; //a<>null int ?b; //b=null int ?c = b+1; //c=null; ?? 是空接合运算符 i ...