金山软件面试题
1. 一个数组{3,4,5,6,3},请输出这个数组的全排列,比如34563、43563、33456...。
2. 编写程序编写程序编写程序编写程序:在O(n)时间复杂度内从数组array[0..n-1]中找出第k个最小的元素。 说明:算法可以对array中的元素进行排序。
3. 综合考察综合考察综合考察综合考察:银行有个存有n个用户编号的文件,每个数都小于n,其中n=10的7次方。每个编号都不重复。 输出:n个数升序排列。约束条件:内存最多有2兆的空间,运行时间复杂度为O(n)
[解决办法]
#include <fstream>
#define MAXSUM 312500
const std::size_t s[32]={
0x00000001,0x00000002,0x00000004,0x00000008,0x00000010,0x00000020,0x00000040,0x00000080,0x00000100,0x00000200,
0x00000400,0x00000800,0x00001000,0x00002000,0x00004000,0x00008000,0x00010000,0x00020000,0x00040000,0x00080000,
0x00100000,0x00200000,0x00400000,0x00800000,0x01000000,0x02000000,0x04000000,0x08000000,0x10000000,0x20000000,
0x40000000,0x80000000
};
void Magnanimitysort()
{
std::size_t *a;
std::size_t b=1;
std::size_t n=0;
std::size_t n1=0,n2=0;
a = (std::size_t*)malloc(sizeof(std::size_t)*MAXSUM);
if(a==NULL)return ;
memset(a,0,sizeof(std::size_t)*MAXSUM);
std::ifstream file("e://acm.txt");
if(!file)
{
std::cout<<"打开文件失败!"<<std::endl;
return ;
}
std::ofstream file2("e://acm2.txt");
if(!file2)
{
std::cout<<"打开文件失败!"<<std::endl;
return ;
}
while(!file.eof())
{
file>>n;
n1=n/32;
n2=n%32;
b=1;
a[n1] = a[n1]
[解决办法]
b<<n2;
}
file.close();
for(b=0;b<MAXSUM;++b)
{
if(a[b]==0)break;
std::size_t i=0;
for(i=0;i<32;i++)
{
std::size_t t = a[b]&s[i];
if( t>0 )
{
//std::cout<<i+b*32<<"\n";
file2<<i+b*32<<"\n";
}
}
}
file2.close();
free(a);
a=NULL;
}
int main()
{
//createfile();
Magnanimitysort();
return 0;
};