Skip to content

Instantly share code, notes, and snippets.

@chenshuo
Created February 13, 2013 17:57
Show Gist options
  • Save chenshuo/4946651 to your computer and use it in GitHub Desktop.
Save chenshuo/4946651 to your computer and use it in GitHub Desktop.
#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