/* * hdu1113/win.cpp * Created on: 2013-6-1 * Author : ben */ #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <ctime> #include <iostream> #include <algorithm> #include <queue> #include <set> #include <map> #include <stack> #include <string> #include <vector> #include <deque> #include <list> #include <functional> #include <numeric> #include <cctype> using namespace std; const int MAXN = 105; string dict[MAXN]; int N = 0; inline bool judge(string s, const char* str) { int len = strlen(str); if(len != s.length()) { return false; } char s1[50], s2[50]; strcpy(s1, s.c_str()); strcpy(s2, str); sort(s1, s1 + len); sort(s2, s2 + len); for(int i = 0; i < len; i++) { if(s1[i] != s2[i]) { return false; } } return true; } int main() { #ifndef ONLINE_JUDGE freopen("data.in", "r", stdin); #endif char str[30]; while(scanf("%s", str) == 1) { if(strcmp(str, "XXXXXX") == 0) { break; } dict[N++] = string(str); } sort(dict, dict + N); while(scanf("%s", str) == 1) { if(strcmp(str, "XXXXXX") == 0) { break; } bool flag = false; for(int i = 0; i < N; i++) { if(judge(dict[i], str)) { printf("%s\n", dict[i].c_str()); flag = true; } } if(!flag) { puts("NOT A VALID WORD"); } puts("******"); } return 0; }