Word Amalgamation
来源:互联网 发布:我的少女时代 知乎 编辑:程序博客网 时间:2024/06/05 10:16
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******
题目大意:给你一堆单词不超过100个作为词典库,遇到XXXXXX时词典库输入结束,开始进行输入单词查找,也是遇到XXXXXX结束输入。单词顺序可以打乱,也就是说只要这个单词的字母跟词典库的可以对应起来就输出词典库中的该单词,如果没有就输出"NOT A VALID WORD每一次输出结果后都输出******。
思路:结构体排序,具体看代码
源代码:
#include <cstdio>#include <cstring>#include <string>#include <iostream>#include <algorithm>#include <stdlib.h>#include <cmath>using namespace std;struct node{ string a; string b;}x[120];bool cmp(node a,node b){ return a.a<b.a;}int main(){ string s,t; int d=0; while(cin >> s){if( s == "XXXXXX"){break;}x[d].a=s;sort(s.begin(),s.end());x[d++].b=s;}sort(x,x+d,cmp);while(cin >> s){if( s == "XXXXXX"){break;}int flag = 0;sort(s.begin(),s.end());for(int i = 0;i < d;i++) { if(x[i].b==s) { cout<<x[i].a<<endl; flag=1; } }if(flag == 0)cout << "NOT A VALID WORD"<<endl;cout << "******"<<endl;}return 0;}
0 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
- 整数中1出现的次数(从1到n整数中1出现的次数)
- <<matlab>>matlab高数实验准备工作
- 三维重建学习之旅(一)
- android中handler和looper的工作原理
- 极光推送
- Word Amalgamation
- HDU2009 求数列的和
- C preprocessor fails sanity check
- qt在linux下开发注意事项
- Android中的Shape使用总结
- java实现整数选择排序
- V4L2命令之 VIDIOC_G_CTRL, VIDIOC_S_CTRL
- H264学习指南
- 加密解密原理