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. Mysql 分别按月, 日为组group,进行统计排序order

    在数据库中我们经经常使用sql语句对表进行简单的统计排序,对于日期字段.我们能够简单的对其进行order. 对于复杂一点的能够按日期中的年.月,日分别进行group,order. 按年份进行group ...

  2. cocos2dx 编写shader 遇到 溢出问题

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

  3. [转]Laravel 4之路由

    Laravel 4之路由 http://dingjiannan.com/2013/laravel-routing/ Laravel 4路由是一种支持RESTful的路由体系, 基于symfony2的R ...

  4. sql语句中BEGIN TRAN...COMMIT TRAN

    BEGIN TRAN标记事务開始  COMMIT TRAN 提交事务  一般把DML语句(select ,delete,update,insert语句)放在BEGIN TRAN...COMMIT TR ...

  5. 89c52串口发送接收小示例

    //串口发送 void sendChar(char *p)//调用前关中断,调用完成后关中断 { while(*p != '\0') { SBUF = *P while(!TI); TI = 0; p ...

  6. Js异步级联选择框实践方法

    HTML: <li> <span>所在地区:</span> <select name="prov" id="ddl_prov&q ...

  7. document.write 存在几个问题?应该注意

    document.write (henceforth DW) does not work in XHTML XHTML 不支持 DW executed after the page has finis ...

  8. sql 参数

    sqlserver :传参数是“@” oracle:是“:” mysql:是“?”

  9. Byte、KB、MB、GB、TB、PB、EB是啥以及它们之间的进率

    它们是存储单位 因为计算机存储单位一般用B,KB.MB.GB.TB.PB.EB.ZB.YB.BB来表示,它们之间的关系是: 位 bit (比特)(Binary Digits):存放一位二进制数,即 0 ...

  10. 0118——UIButtton

    1.Button的定义 UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; Button有六种类型 enum { UI ...