1. 程式人生 > >思路Word Amalgamation

思路Word Amalgamation

Word Amalgamation Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu

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


思路:將輸入的字典詞彙字典排序並用另一陣列儲存,比較時先將字典詞彙和單詞排序,用flag判斷是否有匹配的字典詞彙,沒有則輸出“NOT A VALID WORD

/*小戰*/

#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;

int cmp(const void *a,const void*b) {
	char *s1=(char *)a;
	char *s2=(char *)b;
	return strcmp(s1,s2);
}

int cmp2(char a,char b) {
	return a>b;
}
int main() {
	char dictionary[110][20],dictionary2[110][20],word[20];
	int i = 0;
	while(cin >> dictionary[++i]) {
		if(strcmp(dictionary[i],"XXXXXX")==0) break;
		strcpy(dictionary2[i],dictionary[i]);
	}
	qsort(dictionary,i+1,sizeof(char)*20,cmp);
	qsort(dictionary2,i+1,sizeof(char)*20,cmp);
	while(cin >> word) {
		int t = 0,flag = 0;
		if(strcmp(word,"XXXXXX")==0) break;
		for(int k = 1; k<=i; k++) {
			sort(dictionary[k],dictionary[k]+strlen(dictionary[k]),cmp2);
			sort(word,word+strlen(word),cmp2);
			//cout << word <<endl;
			if(strcmp(dictionary[k],word)==0)
				flag = 1,cout << dictionary2[k]<<endl;
		}
		if(!flag) cout << "NOT A VALID WORD" <<endl;
		cout << "******" <<endl;
	}
	return 0;
}


相關推薦

思路Word Amalgamation

Word Amalgamation Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu

Word Amalgamation (map,字串排序)

Word Amalgamation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2818&

HDU-1113-Word Amalgamation

這題比較方便的解法是使用STL裡的map和set程式碼如下: #include"bits/stdc++.h" using namespace std; map<string,set<string> >mp; string s,t; int main(){ while(c

Word Amalgamation 【HDU

題目連結   題意:我們先給出一系列基礎字串,之後用“XXXXXX”隔開,我們將列寫查詢字串,假如查詢字串換一種排列可以得出上面的字串,那麼,我們就輸出上面的字串,不然輸出:“ NOT A VALID WORD ”。 這就是一道關於STL中map的應用題。 完整程式

POJ 1318 Word Amalgamation

                                                                                                                                        W

HDU1113 POJ1318 UVA642 ZOJ1181 UVALive5328 Word Amalgamation【MAP+排序+水題】

Time Limit:1000MS Memory Limit:10000K Total Submissions:9395 Accepted:4498 Description In millions of newspapers across the United

POJ 1318 Word Amalgamation(我的水題之路——亂序字母匹配)

Word Amalgamation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6130 Accepted: 3051 Description In millions of newspa

leetCode 79.Word Search (詞搜尋) 解題思路和方法

The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically nei

如何去掉word中的回車符??

src play .com auto display 替換 com 符號 ges 打開word界面,點擊頁面左上角的“文件”按鈕,進入到文件欄目中,進行設置。 進入文件之後,在左下角找到並點擊“選項”,進入到word的設置界面中 進入到word選項之後,在左方的菜

call 與 apply,bind 的使用思路

spa obj ply name cal bound add his urn call 與 apply 的區別是 cal 只能一個一個的傳遞參數,apply 是可以通過數組來傳遞參數, bind 需要進行一次額外的聲明, call 實例 var arr = {num:

使用模板生成word文檔

dna head exists pri reat tables hang exceptio website 使用poi-tl根據模板生成word文檔,在porm.xml中添加poi-tl依賴,直接上代碼 import java.io.File; import java.i

LeetCode Length of Last Word

archive n-1 art fine ive lan ets hello style 1. 題目Given a string s consists of upper/lower-case alphabets and empty space characters ‘ ‘

[LeetCode] Word Abbreviation 單詞縮寫

any array number example note long win min which Given an array of n distinct non-empty strings, you need to generate minimal possible

Word 離線發布bolg測試

conf col onf test spa ice 名稱 log 博客 Test From word2016 MetaWeblog API地址: 格式為:http://www.cnblogs.com/你的博客名稱/services/metablogapi.aspx(在

OA修改思路

man 人的 訂單管理 溝通 能力 使用 品牌 工程 信息 總崗: 原有的OA系統主要功能體現在強大的行政管理能力方面。但在CRM系統方面相對來說,沒有太強的行業針對性,雖然有較強大的智能開發平臺,但大部份營銷型企業使用起來會比較困難。 現擬開發的CBS系統,主要是對CR

Word在線編輯功能記錄

在線 富文本 http ueditor 編輯功能 代碼 ued editor 文本編輯 Word在線編輯功能記錄 1, 首先需要導入Word,我們使用轉換html形式 2, 使用UEditor,進行富文本編輯:http://fex.baidu.com/ueditor/ 3,

Fp關聯規則算法計算置信度及MapReduce實現思路

i++ htm [] blank none reat 頻繁項集 可能 term 說明:參考Mahout FP算法相關相關源代碼。算法project能夠在FP關聯規則計算置信度下載:(僅僅是單機版的實現,並沒有MapReduce的代碼)使用FP關聯規則算法計算置信度基於以下

Word Level1 + Level2 套餐來了!

表格制作 目錄 標題樣式 郵件合並 腳註與尾註 版本說明:雖以Word2010講解,不過2007和2013等版本也適用。套餐介紹:此套餐可以讓您系統學習整個Word的常用技巧與實用功能,查找與替換、表格制作、圖文混排、長文檔的編輯、郵件合並、窗體與控件等等。從基礎到進階,從簡單短篇文檔的排

git 對 Microsoft Word 進行版本控制

dcl code 版本控制系統 documents custom ec2 adobe pen you   昨天中國高校發生了一件駭人聽聞的事情,聽說不少高校的校園網用戶連接校園網被勒索病毒給黑了,重要文件全部被加密,必須要支付贖金才能解密,具體新聞可以參見:http://w

思路解析】discuz 帖子設置封面 setthreadcover 表pre_forum_threadimage

新建文件夾 還得 功能 thread mono md5加密 調用 als != 在Discuz 中有一項就是給帖子設置封面,非常多情況下僅僅能通過手動的方式去設置或者用提交POST請求的式去設置; 可是這都是調用DISCUZ的功能設置的; 有的時候並不是萬能的,也