Ultraviolet A-156 Ananagrams
Ananagrams
| Time Limit:3000 MS |
|
Memory Limit:Unknown |
|
64bit IO Format:% Lld & % llu |
Submit Status
Description
Most crossword puzzle fans are usedAnagrams-- Groups of words with the same letters in different orders -- for example OPTS, SPOT, STOP, POTS and POST. some words however do not have this attribute, no matter how you rearrange their letters, you cannot form another word. such words are calledAnanagrams, An example is QUIZ.
Obviusly such definitions depend on the domain within which we are working; you might think that ATHENE is an anagram, whereas any chemist wowould quickly produce ETHANE. one possible domain wocould be the entire English language, but this cocould lead to some problems. one cocould restrict the domain to, say, Music, in which case SCALE becomesRelative ananagram(LACES is not in the same domain) but NOTE is not since it can produce TONE.
Write a program that will read in the dictionary of a restricted domain and determine the relative anagrams. note that single letter words are, ipso facto, relative ananagrams since they cannot be ''rearranged' at all. the dictionary will contain no more than 1000 words.
Input
Input will consist of a series of lines. no line will be more than 80 characters long, but may contain in any number of words. words consist of up to 20 upper and/or lower case letters, and will not be broken into SS lines. spaces may appear freely around words, and at least one space separates multiple words on the same line. note that words that contain the same letters but of differing case are considered to be anagrams of each other, thus tIeD and EdiT are anagrams. the file will be terminated by a line consisting of a single#.
Output
Output will consist of a series of lines. each line will consist of a single word that is a relative anantionary in the input dictionary. words must be output in lexicographic (case-sensitive) order. there will always be at least one relative ananan.pdf.
Sample input
ladder came tape soon leader acme RIDE lone Dreis peat ScAlE orb eye Rides dealer NotE derail LaCeS drIednoel dire Disk mace Rob dries#
Sample output
DiskNotEderaildrIedeyeladdersoon
Enter some words to find all words that meet the following conditions: the word cannot be rearranged by letters to obtain another word in the input text. When determining whether the conditions are met, the letters are case-insensitive, but the input case should be retained in the output and sorted in lexicographically.
#include
#include
#include
#include
#include
#include
#includeusing namespace std;vector
word;map
cnt;string repr(const string &s){string ans = s;for (int i = 0; i < s.size(); i++)ans[i] = tolower(ans[i]);sort(ans.begin(), ans.end());return ans;}int main(){string s;for (int i = 0;; i++){cin >> s;if (s == "#") break;word.push_back(s);string r = repr(s);if (!cnt.count(r)) cnt[r] = 0;cnt[r]++;}vector
ans;for (int i = 0; i < word.size();i++)if (cnt[repr(word[i])] == 1) ans.push_back(word[i]);sort(ans.begin(), ans.end());for (int i = 0; i < ans.size(); i++)cout << ans[i] << endl;return 0;}