Skip to content

Instantly share code, notes, and snippets.

@Jeswang
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jeswang/5f73aaf8625f1ad38d6d to your computer and use it in GitHub Desktop.
Save Jeswang/5f73aaf8625f1ad38d6d to your computer and use it in GitHub Desktop.
find same ints in two file
#include <iostream>
#include <fstream>
#include <bitset>
#include <queue>
#include <vector>
#include <functional>
using namespace std;
bitset<4294967296> bits;
priority_queue<int, vector<int>, greater<int> > res;
int main(int argc, char *argv[]) {
ifstream inf("file1");
long long index;
while(inf>>index) {
index += 2147483648;
bits.set(index);
}
ifstream inf2("file2");
while(inf2>>index) {
index += 2147483648;
if(bits[index]) {
res.push(index-2147483648);
}
}
while(!res.empty()) {
cout<<res.top()<<endl;
res.pop();
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment