U E D R , A S I H C RSS

Classify By Anagram/상규

No older revisions available

No older revisions available



프로그램 소스

~cpp 
#include <string>
#include <list>
#include <map>
#include <algorithm>
#include <iostream>

using namespace std;

class Dictionary
{
private:
	map<string, list<string> > Anagrams;

public:
	void InsertWord(string Word)
	{
		string key = Word;

		sort(key.begin(), key.end());

		if(Anagrams.find(key) == Anagrams.end())
			Anagrams[key] = list<string>();

		Anagrams[key].push_back(Word);
	}

	void OutputAnagram(list<string> Anagram)
	{
		ostream_iterator<string> os_iter(cout, " ");

		copy(Anagram.begin(), Anagram.end(), os_iter);
	}

	void OutputDictionary()
	{
		map<string, list<string> >::iterator iter;

		for(iter = Anagrams.begin() ; iter != Anagrams.end() ; iter++)
		{
			OutputAnagram(iter->second);
			cout << endl;
		}
	}
};

void main()
{
	string word;
	Dictionary dic;

	while(cin >> word)
		dic.InsertWord(word);

	dic.OutputDictionary();
}
P3 1GHz 512MB WinXP VC++7.0 Maximize Speed Optimization 4.1초

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:22:54
Processing time 0.0518 sec