POJ 1318 Word Amalgamation结题报告

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
******

题目大意:输入几行单词作为字典,在XXXX后面输入要查找的单词,然后按顺序输出每个要查找的单词在字典中的各种顺序,每个单词后面都有星号。。。解题思路:用一个数组来储存字典和要查找的单词,用另一个数组记录所有单词按ASC2码的排序,然后逐个枚举,找出相同的输出第一个数组中储存的单词

 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<algorithm>
 4 using namespace std;
 5 char str[103][7];
 6 char in[7];
 7 int cmp(char a,char b)
 8 {
 9
10     return strcmp(a,b)>1;
11 }
12 bool cmp1(char a,char b)
13 {
14     return  a<b;
15 }
16 bool is_same(int len,char *in,char *a)
17 {
18     char out[7];
19     strcpy(out,a);
20     sort(out,out+len,cmp1);
21     if(strcmp(out,in)==0)
22     return true;
23     return false;
24 }
25 int main()
26 {
27     int i=0;
28     while(scanf("%s",str[i++])==1&&strcmp(str[i-1],"XXXXXX")){}
29     int n=i-1;
30     qsort(str,n,sizeof(str[0]),cmp);
31     while(1)
32     {
33         scanf("%s",in);
34         if(strcmp(in,"XXXXXX")==0)
35         break;
36         bool flag=false;
37         int len=strlen(in);
38         sort(in,in+len,cmp1);
39         for(int i=0;i<n;i++)
40         {
41             if(len==strlen(str[i])&&is_same(len,in,str[i]))
42             {
43                printf("%s\n",str[i]);
44                flag=true;
45             }
46         }
47         if(!flag)
48         printf("NOT A VALID WORD\n");
49         printf("******\n");
50     }
51     return 0;
52 }

时间: 2024-11-05 18:40:15

POJ 1318 Word Amalgamation结题报告的相关文章

POJ 1318 Word Amalgamation (字符串 STL大水)

Word Amalgamation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8665   Accepted: 4172 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

poj 1318 Word Amalgamation

Word Amalgamation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9968   Accepted: 4774 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

POJ 1318 Word Amalgamation (简单题)

[题意简述]:首先第一串"XX--"之前的是所谓的字典,然后在它之后的就是我们要查的字串.现在让我们逐个求出这些要查的字串排列后和字典中的字串相同的有哪些,输出出来,没有的话就输出:NOT AVALLID WORD [分析]:理解很简单,我们只需分别对字典中的这些字符串,和我们要查的这些字符串,每一个都排序,然后按位比较,每一位都是相同的那就输出出来就好了. #include<iostream> using namespace std; int n; char word[1

初步了解--状态压缩dp---poj1185炮兵布阵结题报告

好吧,借助poj1185炮兵布阵这题,仔仔细细的了解了一下状态压缩动态规划 首先,借助题目,我们来看看状态压缩是个虾米东西..Ok follow me 一,所谓状态压缩 根据题意,我们得在长度为M 的地图上放置一些大炮(后面简称"放炮",应该不会被和谐吧),那么,首先不考虑山地,我们得把所有的放置方法都找出来,并且注意,这里只对于一行且长度为M(好吧,你可能要问考虑一行,左右互相隔2,互相不在攻击范围,那么上下呢?这里先不急,一步步来) 1,找出所有放炮的方法 假设长度为7,那么看下图

关于填报《国家自然科学基金资助项目结题报告》的补充说明

项目负责人在线提交<结题报告>后,只需打印系统生成的PDF版本,签字后交依托单位. 原<结题报告>撰写提纲与说明中第三项,要求随纸质结题报告提供的附件材料,在电子化后上传即可,无需再随结题报告报送纸质附件材料. <结题报告>中的摘要包括项目摘要和结题摘要两部分,其中项目摘要的内容从计划书中自动生成,结题摘要须以深入浅出的语言简明扼要地概括出项目的精华,如背景.方向.主要内容.重要结果.关键数据及其科学意义等.

poj1185炮兵布阵结题报告--初步了解--状态压缩dp

好吧,借助poj1185炮兵布阵这题,仔仔细细的了解了一下状态压缩动态规划 首先,借助题目,我们来看看状态压缩是个虾米东西..Ok follow me 一,所谓状态压缩 根据题意,我们得在长度为M 的地图上放置一些大炮(后面简称"放炮",应该不会被和谐吧),那么,首先不考虑山地,我们得把所有的放置方法都找出来,并且注意,这里只对于一行且长度为M(好吧,你可能要问考虑一行,左右互相隔2,互相不在攻击范围,那么上下呢?这里先不急,一步步来) 1,找出所有放炮的方法 假设长度为7,那么看下图

《基于Cortex-M4的ucOS-III的应用》课程设计 结题报告

<基于Cortex-M4的ucOS-III的应用>课程设计 结题报告 小组成员姓名:20155211 解雪莹 20155217 杨笛 20155227 辜彦霖 指导教师:娄嘉鹏 一.设计方案及可行性分析 题目要求:ucOS-III的移植:设计三个小实验:单一任务.多任务.并发任务. 1.设计方案 首先运行老师给的范例代码熟悉开发软件和开发板的使用:收集资料简单了解UCOSIII的基本概念,然后进行UCOSIII移植(移植到STM32f407开发板):移植成功后开始进行UCOSIII实例编程(实

20155211课程设计个人结题报告

20155211课程设计个人结题报告 个人贡献 参与课设题目讨论及完成全过程 辅助调试代码 资料收集 撰写小组结题报告 实践过程中的问题及解决: 编译之后出现如下错误:..\OBJ\HZ.axf: error: L6050U: The code size of this image (47788 bytes) exceeds the maximum allowed for this version of the linker. 出现错误的原因是:没有完全破解. 解决办法是:按照D:\实验箱资料2

Codeforces 524 结题报告

打的很快乐的一次比赛hiahiahia, 才A掉4题rating就涨了100+ 距离比赛\(3\)天了, 由于博主实在太颓, 又补掉了\(E\)题, 到现在才发解题报告 A. 语法题, 读入输出就行了 #include<cstdio> #include<algorithm> #include<iostream> #define rd read() #define ll long long using namespace std; int read() { int X =