Most crossword puzzle fans is used to anagrams--groups of words with the same letters in different orders--for E Xample OPTS, SPOT, STOP, POTS and POST. Some words however do not has this attribute, no matter how to rearrange their letters, you cannot form another word. Such words is called ananagrams, a example is QUIZ.
Obviously such definitions depend on the domain within which we is working; You might think this athene is a ananagram, whereas any chemist would quickly produce ethane. One possible domain would be the entire 中文版 language, but this could leads to some problems. One could restrict the domain to, say, Music, in which case scale becomes a relative Ananagram (laces are not in t He same domain) but NOTE was not since it can produce TONE.
Write a program that would read in the dictionary of a restricted domain and determine the relative ananagrams. Note that single letter words is, ipso facto, relative ananagrams since they cannot is ' rearranged ' at all. The dictionary would contain no more than words.
Input
Input would consist of a series of lines. No line would be more than-characters long, but could contain any number of words. Words consist of up to upper and/or lower case letters, and is not being broken across lines. Spaces may appear freely around words, and at least one space separates multiple words on the same line. Note that words this contain the same letters but in differing case is considered to being anagrams of each other, thus TIeD and EdiT are anagrams. The file would be terminated to a line consisting of a single #.
Output
Output would consist of a series of lines. Each line would consist of a single word, a relative ananagram in the input dictionary. Words must is output in lexicographic (case-sensitive) order. There always is at least one relative ananagram.
Sample Input
Ladder came tape soon leader Acme RIDE Lone Dreis Peat Scale orb eye Rides dealer NotE derail laces Driedn Oel dire Disk Mace Rob dries#
Sample Output
Disknotederaildriedeyeladdersoon
The problem is completely violent.
Put the word sort into map and count the occurrences.
The output of the time to judge again.
#include <cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<string>#include<vector>#include<map>using namespaceStd;vector<string>dict;stringWord;map<string,int>Hash;stringStandardstrings) { for(inti =0; I < s.length (); ++i) s[i]=ToLower (S[i]); Sort (S.begin (), S.end ()); returns;}intMain () {hash.clear (); while(Cin >>word) { if(Word = ="#") Break; Dict.push_back (word); stringTMP =Standard (word); if(!hash.count (TMP)) hash[tmp] =0; Elsehash[tmp]++; } sort (Dict.begin (), Dict.end ()); for(inti =0; I < dict.size (); ++i)if(Hash[standard (dict[i]) = =0) cout<< Dict[i] <<"\ n"; return 0;}
"UVa 156" Ananagrams