U E D R , A S I H C RSS

Classify By Anagram/인수


1. 1st Source

#include <map>
#include <string>
#include <iostream>
#include <fstream>

using namespace std;

class Anagram
{
private:
	typedef map< string, map<char, int> >::iterator MSMCII;
	typedef map< char, int > MCI;

	map< string, map<char, int> > _anagramTable;
public:
	void CalWhatAnagram(const string& str)
	{
		MCI howManyEachAlphabet;
		for(int i = 0 ; i < str.size() ; ++i)	
			howManyEachAlphabet[ str[i] ] += 1;		
		_anagramTable[str] = howManyEachAlphabet;
	}
	void Show()
	{
		while( !_anagramTable.empty() )
		{
			MCI value = _anagramTable.begin()->second;

			for(MSMCII i = _anagramTable.begin() ; i != _anagramTable.end() ; )
			{
				if(i->second == value)
				{
					cout << i->first << " ";
					_anagramTable.erase(i++);
				}
				else
				{
					++i;
				}
			}
			cout << endl;
		}
	}
};


int main()
{
	Anagram anagram;

	ifstream fin("input.dat");

	string t;

	while(!fin.eof())
	{
		getline(fin, t);
		anagram.CalWhatAnagram(t);
	}
	anagram.Show();

	fin.close();

	return 0;
}

2. 1st

  • , , <, 그 > Pair Pair .(--; 군)
    • , n개, 균 길 m , Pair Θ(mn) . map Θ(n) .
  • map 객 , anagram .( .)
    • . Θ(n*n) .
  • ... . Θ(n*n) .

3. 1st 개

  • .
  • 2 .
  • ; 3; 게 10 ..; 5 ..;



4. 2nd Source

~cpp 
#include <map>
#include <string>
#include <vector>
#include <iostream>
#include <fstream>

using namespace std;

class Anagram
{
private:
	typedef map<char, int> MCI;
	typedef vector<string> LS;
	typedef map< MCI, LS > MALS;
	
	typedef MALS::iterator MALSI;
	typedef LS::iterator LSI;

	MALS _anagramTable;

	MCI CalculateWhatAnagram(const string& str)
	{
		MCI howManyEachAlphabet;
		for(int i = 0 ; i < str.size() ; ++i)	
			howManyEachAlphabet[ str[i] ] += 1;		
		return howManyEachAlphabet;
	}
public:
	void BoundAnagram(char* fileName)
	{
		ifstream fin(fileName);
		string str;
		while(!fin.eof())
		{
			getline(fin, str);
			_anagramTable[ CalculateWhatAnagram(str) ].push_back(str); 
		}
	}
	void ShowAnagram()
	{
		for(MALSI i = _anagramTable.begin() ; i != _anagramTable.end() ; ++i)
		{
			for(LSI j = (i->second).begin() ; j != (i->second).end(); ++j)
			{
				cout << *j << " ";
			}
			cout << endl;
		}
	}
};

int main()
{
	Anagram ana;
	ana.BoundAnagram("input.dat");
	ana.ShowAnagram();
	return 0;
}

5. 2nd

  • key : map , value : 그 string list. .
  • 1st .. 90.
  • , n, 균 길 m , : Θ(mn), : Θ(n) m n ~~~~~ . Θ(n) ?--; .

6. 2nd 개

  • .
  • 1(2) . 까. 게 10 ..--; 10 걸까.
  • 까 10(2) . 길--;
  • . "~~~ inputed!" 10, 1 .
  • list vector 꾸고 6.2.

7. 금까

  • .. . .
  • .
  • .--;

8. 결과

  • 17 6.2




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