In millions of newspapers across the United States there is a word game calledJumble. 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 file contains four parts:
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 sentinelXXXXXXcontains uppercaseX'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 ******
#define RUN #ifdef RUN #include<stdio.h> #include<stdlib.h> #include<string.h> int n; // n为单词的总数 // word数组的每一行都存放着词典中的一个单词 char word[2000][10], sorted[2000][10]; /* 基本思想: 借组qsort函数,先把在词典中所有的单词排序, 再对每一个单词进行字母排序, 把结果放在sorted[]数组中 对于新输入需要判断的单词,直接和sorted数组里面的各个单词比较即可 */ // 字符比较函数 int cmp_char(const void* _a, const void* _b) { char* a = (char*)_a; char* b = (char*)_b; return *a - *b; } // 字符串比较函数 int cmp_string(const void* _a, const void* _b) { char* a = (char*)_a; char* b = (char*)_b; return strcmp(a, b); } int main() { #ifndef ONLINE_JUDGE freopen("642.in", "r", stdin); freopen("642.out", "w", stdout); #endif n = 0; // n为单词总数 for(;;) { scanf("%s", word[n]); // 记录每一个定义的单词 if(word[n][0] == 'X') break; // 结束记录 n++; } // 此步可省略 qsort(word, n, sizeof(word[0]), cmp_string); // 对每一个单词进行字母层面的排序,使每一个单词都是alphabetacal for(int i = 0; i < n; i++) { strcpy(sorted[i], word[i]); qsort(sorted[i], strlen(sorted[i]), sizeof(char), cmp_char); } char s[10]; while(scanf("%s", s)!=EOF && s[0]!='X') { // 对读入的每一个乱序单词进行排序 qsort(s, strlen(s), sizeof(char), cmp_char); int found = 0; // 与词典库中的每一个已定义的单词进行比较 for(int i = 0; i < n; i++){ if(strcmp(sorted[i], s) == 0) { found = 1; printf("%s\n", word[i]); } } if(!found) printf("NOT A VALID WORD\n"); printf("******\n"); } return 0; } #endif
相关推荐
sqlite-amalgamation-3.7.3.tar.rar
sqlite-amalgamation-3_7_0.zip"sqlite-amalgamation-3_7_0.zip
sqlite-amalgamation-3_7_2
sqlite-amalgamation-3.8.8.tar.tgz 官网下载 ,含源代码,文档
sqlite-amalgamation-3.7.3.tar, 从国外站点下个东西不好下~ 好不容易下来了~ 分享下~ 需要的拿去~
sqlite-amalgamation-3.6.11.tar.gz
linux上,编译安装svn组件sqlite-amalgamation
sqlite最新源码压缩包 官网下载太慢了,上传一个备份 ...sqlite-amalgamation-3300100.zip (2.24 MiB) C source code as an amalgamation, version 3.30.1. (sha1: ff9b4e140fe0764bc7bc802facf5ac164443f517)
sqlite-amalgamation-3340000
SQlite源码,版本是3.14.2.
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 ...
sqlite简单操作小型数据库源代码,对于小系统完全满足。 sqlite3.h、sqlite3.c 主要两个数据库操作代码文件。 源代码仅供参考,可去官网下载。
sqlite3.10.1源码,SQLite Release 3.8.10.1 On 2015-05-09
sqlite 3.37源码
SQLite Release 3.8.9 On 2015-04-08 Add VxWorks-7 as an officially supported and tested platform. Added the sqlite3_status64() interface. Fix memory size tracking so that it works even if SQLite uses ...
非常优秀的嵌入式数据库系统完整源代码。非常有价值!
sqlite-amalgamation-3070500
文件名: sqlite-amalgamation-3420000.zip
sqlite是一个开源的嵌入式文件数据库,sqlite以动态链接库的方式供应用程序调用,所有的数据库对象都存储在同一个文件中。 sqlite动态库非常小,最新的3.8.11版本也只有500k左右。sqlite虽然小,但功能并不弱,它...
sqlite-amalgamation-3.6.13.tar.gz