Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <iterator>
- #include <algorithm>
- #include <set>
- #include <cctype>
- using namespace std;
- set<string> dict;
- string clean(const string &s) {
- string res;
- for (char c : s)
- if (isalpha(c) || (c == '\''))
- res += (char)tolower(c);
- return res;
- }
- void check(const string & s) {
- string cleanword = clean(s);
- if (! dict.count(cleanword) )
- cout << s << endl;
- }
- int main(int argc, char **argv) {
- ifstream fin(argv[1]);
- if (!fin) {
- cerr << "No file " << argv[1] << endl;
- return -1;
- }
- typedef istream_iterator<string> string_iterator_over;
- vector<string> dv;
- ifstream dictin("/usr/share/dict/words");
- for_each(string_iterator_over(dictin), string_iterator_over(),
- [&dv] (const string &s) { dv.push_back(s); } );
- dictin.close();
- dict = set<string>(begin(dv), end(dv));
- for_each(string_iterator_over(fin), string_iterator_over(), check);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement