博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu-----(1113)Word Amalgamation(字符串排序)
阅读量:6340 次
发布时间:2019-06-22

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

Word Amalgamation

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

Total Submission(s): 2586    Accepted Submission(s): 1246

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
代码:
1 #include
2 #include
3 using namespace std; 4 struct node 5 { 6 char old[8]; 7 char ne[8]; 8 bool operator <(const node &a)const{ 9 if(strcmp(old,a.old)<0) return 1;10 return 0;11 }12 }str[105];13 int main(){14 int i=0;15 //freopen("test.in","r",stdin);16 while(scanf("%s",&str[i].old)&&str[i].old[0]!='X'){17 strcpy(str[i].ne,str[i].old);18 sort(str[i].ne,str[i].ne+strlen(str[i].ne));19 i++;20 }21 int n=i;22 sort(str,str+n);23 char ss[8];24 while(scanf("%s",ss)&&ss[0]!='X'){25 sort(ss,ss+strlen(ss));26 int cnt=0;27 for(int i=0;i
View Code

 

转载地址:http://hihoa.baihongyu.com/

你可能感兴趣的文章
mysql的pid文件出现问题
查看>>
计算rem单位
查看>>
第七章 大网高级 ASA
查看>>
rsync+inotify触发式远程同步
查看>>
优秀设计师应当知道的几大UI设计原则(一)
查看>>
mongodb高级查询
查看>>
struts2.1 struts.devMode BUG解决方案
查看>>
日本法院裁定三星诉苹果专利侵权案败诉
查看>>
Windows Server 2012R2 桌面体验问题直通车
查看>>
Springboot配置文件读取报错Configuration property name 'projectUrl' is not valid:
查看>>
HTTP状态码
查看>>
今天的学习
查看>>
面试必问之JVM原理
查看>>
mysql主主同步+Keepalived
查看>>
研究音频编解码要看什么书
查看>>
tomcat远程调试配置
查看>>
QuartZ Cron表达式
查看>>
性能测试工具VTune的功能和用法介绍
查看>>
音频视频组件Audio DJ Studio for .NET更新至v10.0.0.0丨附下载
查看>>
Pig的输入输出及foreach,group关系操作
查看>>