Advertisement
Guest User

Untitled

a guest
Feb 13th, 2012
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.20 KB | None | 0 0
  1. #include <iostream>                                                                                                                                                                                  
  2. #include <fstream>
  3. #include <iterator>
  4. #include <algorithm>
  5. #include <set>
  6. #include <cctype>
  7. using namespace std;
  8.  
  9. set<string> dict;
  10.  
  11. string clean(const string &s) {
  12.     string res;
  13.     for (char c : s)  
  14.         if (isalpha(c) || (c == '\''))
  15.             res += (char)tolower(c);
  16.     return res;
  17. }
  18.  
  19. void check(const string & s) {
  20.     string cleanword = clean(s);
  21.     if (! dict.count(cleanword) )
  22.         cout << s << endl;
  23. }
  24.  
  25. int main(int argc, char **argv) {
  26.     ifstream fin(argv[1]);
  27.     if (!fin) {
  28.         cerr << "No file " << argv[1] << endl;
  29.         return -1;
  30.     }  
  31.  
  32.     typedef istream_iterator<string> string_iterator_over;
  33.  
  34.     vector<string> dv;
  35.     ifstream dictin("/usr/share/dict/words");
  36.     for_each(string_iterator_over(dictin), string_iterator_over(),
  37.             [&dv] (const string &s) {  dv.push_back(s); } );
  38.     dictin.close();
  39.          
  40.     dict = set<string>(begin(dv), end(dv));
  41.  
  42.     for_each(string_iterator_over(fin), string_iterator_over(), check);
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement