博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
杭电1113--Word Amalgamation
阅读量:7280 次
发布时间:2019-06-30

本文共 3268 字,大约阅读时间需要 10 分钟。

Word Amalgamation

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

Total Submission(s): 2845    Accepted Submission(s): 1369

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
******
 

 

Source
 

 

Recommend
Eddy   |   We have carefully selected several similar problems for you:            
<1>输入几个字符串,(按字典序排好)→ 用作字典;
<2>输入无序单词,查找;
<3>输出;
1 #include 
2 #include
3 #include
4 using namespace std; 5 6 struct dic 7 { 8 int n ; 9 char str[10]; 10 };11 dic num[110];12 13 bool cmp(char c, char b)14 {15 return c > b; 16 }17 18 bool cpm(dic str, dic n)19 {20 return strcmp(str.str, n.str) < 0;21 }22 int main()23 {24 char ch[10];25 char s[10];26 char ac[110][10];27 int i, j,total=0;28 while(~scanf("%s",ch)&&strcmp(ch, "XXXXXX")!=0)29 {30 strcpy(num[total++].str, ch);31 //i++;32 } 33 sort(num, num+total, cpm);34 //printf("%d\n", total);35 while(~scanf("%s",ch),strcmp(ch, "XXXXXX")!=0)36 {37 int flag=0 ,len;38 int nel=strlen(ch);39 sort(ch, ch+nel, cmp);40 for(i=0; i<=total; i++)41 {42 strcpy(s, num[i].str);43 len = strlen(s);44 sort(s, s+len, cmp);45 if(strcmp(s, ch) == 0)46 {47 printf("%s\n", num[i].str);48 flag++;49 }50 //else51 //printf("NOT A VALID WORD\n");52 }53 if(flag==0)54 printf("NOT A VALID WORD\n");55 /*else56 {57 sort(ac,ac+flag,cpm);58 for(i=0; i

 

 

转载于:https://www.cnblogs.com/soTired/p/4676641.html

你可能感兴趣的文章
APICloud框架——总结一下最近开发APP遇到的一些问题 (二)
查看>>
python day04
查看>>
JVM的内存区域划分
查看>>
MySQL基础
查看>>
1595:Symmetry
查看>>
你应该知道的大数据领域12大动向
查看>>
R-CNN for Small Object Detection
查看>>
IF函数多个条件判断及嵌套
查看>>
代码搬移
查看>>
ajax请求code:200但是进入error函数
查看>>
软件图标显示不正常的问题
查看>>
Golang websocket
查看>>
关于编码:Unicode/UTF-8/UTF-16/UTF-32
查看>>
C++ OpenSSL 之三:生成CSR文件
查看>>
amaze ui响应式辅助
查看>>
C++getline使用
查看>>
Spinner使用二
查看>>
android 隐藏输入法键盘
查看>>
Android jni 中打印logcat日志
查看>>
SSL和keystore生成、导入等配置
查看>>