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.0150 sec