Created
February 13, 2013 17:57
-
-
Save chenshuo/4946651 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <algorithm> | |
#include <fstream> | |
#include <iostream> | |
#include <string> | |
#include <vector> | |
using namespace std; | |
bool covered(const vector<string>& filters, const string& line) | |
{ | |
typedef vector<string>::const_iterator Iterator; | |
Iterator filter = lower_bound(filters.begin(), filters.end(), line); | |
if (filter != filters.end() && *filter == line) | |
return true; | |
if (filter != filters.begin()) | |
{ | |
--filter; | |
if (line.size() >= filter->size() | |
&& equal(filter->begin(), filter->end(), line.begin())) | |
return true; | |
} | |
return false; | |
} | |
int main(int argc, char* argv[]) | |
{ | |
if (argc == 3) | |
{ | |
vector<string> filters; | |
{ | |
ifstream in2(argv[2]); | |
string filter; | |
while (getline(in2, filter)) | |
{ | |
reverse(filter.begin(), filter.end()); | |
if (filter[filter.size()-1] != '.') | |
filter.push_back('.'); | |
filters.push_back(filter); | |
} | |
} | |
sort(filters.begin(), filters.end()); | |
{ | |
ifstream in1(argv[1]); | |
string line; | |
while (getline(in1, line)) | |
{ | |
reverse(line.begin(), line.end()); | |
if (line[line.size()-1] != '.') | |
line.push_back('.'); | |
if (!covered(filters, line)) | |
{ | |
cout << "remain " << line << '\n'; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment