#include<iostream>
#include<fstream>
#include<string>
#include"time.h"
using namespace std;
#define N 10000000
#define BITSTEP 32
#define MASK 0x1F
#define shift 5
int bit[N/BITSTEP+1];
void clr(int i)
{
bit[i>>shift]&=~(1<<(i&MASK));
}
void set(int i)
{
bit[i>>shift]|=(1<<(i&MASK));
}
int test(int i)
{
int tmp=bit[i>>shift]&(1<<(i&MASK));
return tmp>>(i&MASK);
}
int main(void)
{
string ifile,ofile;
fstream infile;
fstream outfile;
int a;
cin>>ifile;
cin>>ofile;
time_t str_time=time(NULL);
char * str=ctime(&str_time);
infile.open(ifile.c_str());
if(!infile)
{
cerr<<"error: can not open file :"<<ifile<<endl;
return -1;
}
for(int i=0;i<N;i++){
// infile<<i<<endl;
clr(i);
}
while(infile>>a)
{
//cout<<a<<endl;
set(a);
// cout<<bit[a>>shift]<<endl;
}
outfile.open(ofile.c_str());
if(!outfile)
{
cerr<<"can not open outfile :"<<ofile<<endl;
}
time_t net_time=time(NULL);
char * net=ctime(&net_time);
for(i=0;i<N;i++)
{
if(test(i)==1)
//cout<<test(i)<<endl;
outfile<<i<<endl;
}
time_t end_time=time(NULL);
char * end=ctime(&end_time);
double dif=difftime(str_time,end_time);
double difnet=difftime(str_time,net_time);
//double end_time=_getsystime(&t);
cout<<end<<":"<<net<<":"<<str<<":"<<dif<<":"<<difnet<<endl;
}
位图排序
最新推荐文章于 2022-05-08 20:56:50 发布