Revision: 1193
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at September 22, 2006 05:34 by wicked
Initial Code
#include <fstream>
#include <iostream>
#include <set>
#include <string>
using namespace std;
struct comparator {
bool operator()(const string &a, const string &b) {
if(a.length() == b.length())
return a<b;
return a.length()<b.length();
}
};
int main()
{
ifstream in("/usr/share/dict/words");
set<string,comparator> sorter;
string s;
while(in >> s) if(tolower(s[0]) == 'q') sorter.insert(s);
int max = 0;
for(set<string,comparator>::iterator word = sorter.begin(); word != sorter.end(); ++word) {
if(word->length() > max) {
max = word->length();
cout << "Words of length " << max << '\n';
}
cout << *word << " " << word->length() << "\n";
}
return 0;
}
Initial URL
http://steve.yegge.googlepages.com/ruby-tour
Initial Description
Initial Title
Stevey's sorting program in C++
Initial Tags
Initial Language
C++