HDU_1113Word Amalgamation
来源:互联网 发布:花生壳linux版客户端 编辑:程序博客网 时间:2024/06/04 17:48
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 <string> #include <map> #include <algorithm> using namespace std; map<string, string> str; string s, t; int main() { while(cin >> s && s != "XXXXXX") { t = s; sort(s.begin(), s.end()); str[t] = s; } while(cin >> s && s != "XXXXXX") { bool flag = 0; t = s; sort(s.begin(), s.end()); for(map<string, string>::iterator it=str.begin(); it!=str.end(); ++it) if(it->second == s) { cout << it->first << endl; flag = 1; } if(flag == 0) cout << "NOT A VALID WORD\n"; cout << "******\n"; } return 0; }思路解析:
学习了一天的map,至今感觉意犹未尽。。。我的VC编译器下架了,Code:: Blocks上市了。呵呵,只想说好强大。。。
参考这道题,只是学习了一些皮毛而已。
第一个XXXXXX前面的是给出的字典,之后的是查询的关键词语,目标是找到字典中与其有相同的字母所构成的字符
串。两者字符长度一样,参考输出,多个满足时按字典序输出所有满足的。
0 0
- HDU_1113Word Amalgamation
- 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
- 软件开发过程与思想
- 五一九天假期ACM集训记录【4月27日—第二天】
- poj 2992 Divisors(求组合数的因子个数)
- 总结
- 1011.最大连续子序列
- HDU_1113Word Amalgamation
- Java 内部类基本用法
- OO开发思想:面向对象的开发方法(Object oriented,OO)
- 1257 hdu
- java书籍Top10另一说法
- Python核心编程第六章笔记
- openssl1.0.1g安装
- 安装ubuntu时出现 “正在探测文件系统。。”这此处卡住了。。。
- What is the difference between /dev/ttyUSB and /dev/ttyACM?