Word Amalgamation hdu1113
来源:互联网 发布:网络家装公司 编辑:程序博客网 时间:2024/06/01 11:36
Word Amalgamation
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 7 Accepted Submission(s) : 4
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
tarpgivenscorerefundonlytrapworkearncoursepepperpartXXXXXXresconfudreaptrsettoresucXXXXXX
Sample Output
score******refund******parttarptrap******NOT A VALID WORD******course******字符串问题,本题的大意就是在多个单词中,查找输入的混乱的单词,并查找在原来的字典中是否存在这个单词,如果存在多个就按字典序输出代码如下:#include <cstdio>#include <iostream>#include <algorithm>#include <map>#include <cstring>#include <queue>using namespace std;#define maxn 120#define maxx 10map<string,priority_queue<string,vector<string>,greater<string> > > mapp;<span style="white-space:pre"></span>//map存储输入的字典,key为排序之后的单词,value为原始的单词,并在存储value的时候用priority_queue进行对多个单词排序。int main(){char a[maxx],b[maxx];map<string,priority_queue<string,vector<string>,greater<string> > >::iterator iter;<span style="white-space:pre"></span>//定义迭代器。while(1)<span style="white-space:pre"></span>//输入字典{scanf("%s",a);if(strcmp(a,"XXXXXX")==0)break;strcpy(b,a);sort(a,a+strlen(a));mapp[a].push(b);}while(1)<span style="white-space:pre"></span>//对测试实例处理并查找输出。{scanf("%s",a);if(strcmp(a,"XXXXXX")==0)break;sort(a,a+strlen(a));iter = mapp.find(a);<span style="white-space:pre"></span>//查找单词a所在的位置,并返回迭代器iter。if(iter==mapp.end())printf("NOT A VALID WORD\n");else{int n=iter->second.size();for(int i=0;i<n;i++)<span style="white-space:pre"></span>//输出优先队列中的单词。{cout<<iter->second.top()<<endl;iter->second.pop();}}cout<<"******"<<endl;}return 0;}
0 0
- hdu1113 Word Amalgamation
- Word Amalgamation hdu1113
- HDU1113 Word Amalgamation
- HDU1113 POJ1318 UVA642 ZOJ1181 Word Amalgamation
- hdu1113 Word Amalgamation(详细解释--map和string的运用)
- Word Amalgamation
- Word Amalgamation
- Word Amalgamation
- HDU1113
- 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
- STL系列之二 stack栈
- 用异或来交换两个变量能提高速度是错误的
- error LNK2019: 无法解析的外部符号 opencv
- jQuery显示隐藏
- Dijstra算法的代码实现及解释(最短路径问题)
- Word Amalgamation hdu1113
- (2.1.3)Linux知识:常见指令
- GPRS实现pppd拨号
- #Java基础语法#(3)控制结构
- Python 第一课
- 全反反选样式+数据隐藏域
- 寻觅大小S
- 第一章
- 房间安排