UVA156Ananagrams

uva-156
题目:
Most crossword puzzle fans are used toanagrams— groups of words with the same letters in differentorders — for example OPTS, SPOT, STOP, POTS and POST. Some words however do not have thisattribute, no matter how you rearrange their letters, you cannot form another word. Such words arecalledananagrams, an example is QUIZ.Obviously such definitions depend on the domain within which we are working; you might thinkthat ATHENE is an ananagram, whereas any chemist would quickly produce ETHANE. One possibledomain would be the entire English language, but this could lead to some problems. One could restrictthe domain to, say, Music, in which case SCALE becomes arelative ananagram(LACES is not in thesame 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 relativeananagrams. 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.InputInput will consist of a series of lines. No line will be more than 80 characters long, but may contain anynumber of words. Words consist of up to 20 upper and/or lower case letters, and will not be brokenacross lines. Spaces may appear freely around words, and at least one space separates multiple wordson the same line. Note that words that contain the same letters but of differing case are considered tobe anagrams of each other, thus ‘tIeD’ and ‘EdiT’ are anagrams. The file will be terminated by a lineconsisting of a single ‘#’.OutputOutput will consist of a series of lines. Each line will consist of a single word that is a relative ananagramin the input dictionary. Words must be output in lexicographic (case-sensitive) order. There will alwaysbe at least one relative ananagram.Sample Inputladder came tape soon leader acme RIDE lone Dreis peatScAlE orb eye Rides dealer NotE derail LaCeS drIednoel dire Disk mace Rob dries#Sample OutputDiskNotEderaildrIedeyeladdersoon
ac代码:

#include
#include
#include
#include
#include
#include
#include
using namespace std;
const int N=1000+10;
map d;
vector word,ret;
string dealstr(const string &s ){
	string str=s;
	int len=str.size();
	for(int i=0;i>s){
		if(s[0]=='#') break;
		string str=dealstr(s);
		d[str]++;
		word.push_back(s);
	}
	int l=word.size();
	for(int i=0;i

你可能感兴趣的:(uva,stl)