Word Amalgamation
来源:互联网 发布:用友软件工资 编辑:程序博客网 时间:2024/05/16 01:04
Word Amalgamation
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1952 Accepted Submission(s): 911
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.
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
tarpgivenscorerefundonlytrapworkearncoursepepperpartXXXXXXresconfudreaptrsettoresucXXXXXX
Sample Output
score******refund******parttarptrap******NOT A VALID WORD******course******方法一:/*思路:我的思路很笨,先排序,再一个一个的匹配*/#include<iostream>#include<cstdio>using namespace std;int cmp(const void *a,const void *b){//按字典升序排序char *c=(char *)a;char *d=(char *)b;for(int i=0;i<strlen(c);i++)if(c[i]!=d[i])return c[i]-d[i];return c[0]-d[0];}int main(){char a[222][8];char b[8];int k=0;while(gets(a[k++])&&strcmp(a[k-1],"XXXXXX"));qsort(a,k,sizeof(a[0]),cmp);while(gets(b)&&strcmp(b,"XXXXXX")){int vi[10];int tag=0,tag1=0;for(int i=0;i<k;i++){tag=0;memset(vi,0,sizeof(vi));if(strlen(a[i])==strlen(b)){for(int j=0;j<strlen(a[i]);j++){tag=0;for(int l=0;l<strlen(b);l++)if(a[i][j]==b[l]&&!vi[l]){vi[l]=1;tag=1;break;}if(!tag)break;}}if(tag){tag1=1;cout<<a[i]<<endl;}}if(!tag1)cout<<"NOT A VALID WORD"<<endl;cout<<"******"<<endl;}return 0;}方法二:/*思路:使用map容器,和string类的排序方法*/#include<iostream>#include<map>#include<string>#include<algorithm>using namespace std;map<string,string>m;int main(){string a;string end="XXXXXX";while(cin>>a&&a!=end){string t=a;sort(a.begin(),a.end());m[t]=a;}while(cin>>a&&a!=end){sort(a.begin(),a.end());int flag=0;for(map<string,string>::iterator it=m.begin();it!=m.end();it++)if(it->second==a){flag=1;cout<<it->first<<endl;}if(!flag)cout<<"NOT A VALID WORD"<<endl;cout<<"******"<<endl;}return 0;}
- Word Amalgamation
- Word Amalgamation
- Word Amalgamation
- Word Amalgamation源程序
- fjnu 1147 Word Amalgamation
- POJ1318 Word Amalgamation
- POJ 1318 Word Amalgamation
- ZOJ 1181Word Amalgamation
- POJ 1318 Word Amalgamation
- poj 1318 Word Amalgamation
- 1318 Word Amalgamation
- POJ 1113 Word Amalgamation
- HDU 1113 Word Amalgamation
- POJ 1318 Word Amalgamation
- UVA 642 - Word Amalgamation
- ZOJ 1181 Word Amalgamation
- hdu 1113 Word Amalgamation
- UVa642 - Word Amalgamation
- IT人与技术
- Android反编译xml文件
- 有关C#的dos命令
- openGL
- 分享50个使你成为高级javascript开发者的jQuery的代码开发技巧
- Word Amalgamation
- 拍七游戏 许多人都曾经玩过“拍七”游戏。 规则是:大家依次从1开始顺序数数,数到含有7或7的倍数的要拍手或其它规定的方式表示越过 (比如:7,14,17等都不能数出),下一人继续数下面的数
- 1.最小根文件系统制作
- 常用JavaScript代码(持续更新) 续1
- 常用JavaScript代码(持续更新) 续2
- 一位过来人讲述了他的职业故事
- 利用MQ实现大文件交换
- iOS网络编程之同步、异步、请求队列
- jQuery点击tr实现checkbox