Skip to content

Instantly share code, notes, and snippets.

@excavador
Created January 9, 2014 15:00
Show Gist options
  • Save excavador/8335401 to your computer and use it in GitHub Desktop.
Save excavador/8335401 to your computer and use it in GitHub Desktop.
#include <fstream>
#include <iostream>
#include <unordered_set>
#include <boost/format.hpp>
typedef std::unordered_set<uint64_t> Set;
void load(Set& data, const std::string& filename)
{
uint64_t current;
std::ifstream file(filename);
while(file >> current)
{
data.insert(current);
}
}
int handle(const Set& data, std::istream& in, std::ostream& out)
{
uint64_t current;
while(in >> current)
{
const char* result = data.count(current) ? "1\n" : "0\n";
out << result << std::flush;
}
return 0;
}
int main(int argc, char* argv[])
{
try
{
assert(argc == 2);
Set set;
load(set, argv[1]);
std::cerr << "Ready\n" << std::flush;
return handle(set, std::cin, std::cout);
}
catch(const std::exception& e)
{
std::cerr << boost::format("Error: %1%") % e.what() << std::endl;
return 1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment