Results 1 to 12 of 12
Thread: ...
Hybrid View
-
6th July 2004 23:03 #1
-
6th July 2004 23:31 #2
Join Date: Aug:2003
Location:
Posts: 8,103
-
7th July 2004 11:55 #3
-
7th July 2004 12:24 #4
Pa3KaTaH, , 2 !
Word XP , CTRL+H (Replace) . *****. Replace All , 1024 . ...
-
7th July 2004 14:44 #5
-
7th July 2004 15:07 #6
-
7th July 2004 15:31 #7
-
7th July 2004 22:50 #8
-
8th July 2004 01:19 #9
-
8th July 2004 14:27 #10
-
8th July 2004 14:31 #11
-
9th July 2004 17:23 #12
, C++ ( Boost STL):
.EXECode:#include <iostream> #include <map> #include <set> #include <sstream> #include <string> #include <boost/tokenizer.hpp> using namespace std; using namespace boost; typedef map<string, int> WordMap; struct Word { int count; const string *str; Word(int count, const string *str) : count(count), str(str) { } friend bool operator<(const Word& lhs, const Word& rhs) { return (lhs.count>rhs.count) || ((lhs.count==rhs.count) && (*lhs.str<*rhs.str)); } }; typedef set<Word> WordSet; int main() { ostringstream ostr; cin >> ostr.rdbuf(); string str = ostr.str(); tokenizer<> tok(str); WordMap wordMap; for (tokenizer<>::iterator it = tok.begin(); it != tok.end(); ++it) ++wordMap[*it]; WordSet wordSet; for (WordMap::iterator it = wordMap.begin(); it != wordMap.end(); ++it) wordSet.insert(Word(it->second, &it->first)); for (WordSet::iterator it = wordSet.begin(); it != wordSet.end(); ++it) cout << it->count << " " << *it->str << endl; }
:
wc <filename.txt





Reply With Quote


7th May 2023, 16:02 in PC