Posted on 2008-04-18 09:50
superman 阅读(278)
评论(0) 编辑 收藏 引用 所属分类:
ZOJ
1 /* Accepted 1181 C++ 00:00.00 848K */
2 #include <string>
3 #include <iostream>
4 #include <algorithm>
5
6 using namespace std;
7
8 int main()
9 {
10 string s, dict[100];
11 int n = 0, cnt[100][26] = {0};
12
13 while( (cin >> s) && s != "XXXXXX" )
14 dict[n++] = s;
15
16 sort( dict, dict + n );
17
18 for( int i = 0; i < n; i++ )
19 for( int j = 0; j < dict[i].size(); j++ )
20 cnt[i][dict[i][j] - 97]++;
21
22 while( (cin >> s) && s != "XXXXXX" )
23 {
24 int x[26] = {0};
25 for( int i = 0; i < s.size(); i++ )
26 x[s[i] - 97]++;
27 bool find = false;
28 for( int i = 0; i < n; i++ )
29 if( s.size() == dict[i].size() )
30 {
31 int j;
32 for( j = 0; j < 26; j++ )
33 if( cnt[i][j] != x[j] )
34 break;
35 if( j == 26 )
36 {
37 find = true;
38 cout << dict[i] << endl;
39 }
40 }
41 if( find == false )
42 cout << "NOT A VALID WORD" << endl;
43 cout << "******" << endl;
44 }
45
46 return 0;
47 }
48