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) 린다.
- 기, 단 갯를 n개, 단 균 길를 m라 면, 것 떤 Pair가 단는데 Θ(mn) 린다. 다 그것 map 는데 Θ(n) 린다.
- 력때는 map 객를 면, 부 끝까 돌면 anagram 다.( 방법 같기는 다.)
- 대로 . Θ(n*n) 리는 는다.
- 대로 . Θ(n*n) 리는 는다.
- 반로 단 갯는 단 길보다는... 무래 것다. 고리 Θ(n*n) 린다고 다.
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 린다.