
搜索引擎工程师面试题.doc
13页1.给两个数组和他们的大小,还有一动态开辟的内存,求交集,把交集放到动态内存 dongtai,并且返回交集个数long jiaoji(long* a[],long b[],long* alength,long blength,long* dongtai[])2.单连表的建立,把'a'--'z'26 个字母插入到连表中,并且倒叙,还要打印!方法 1:typedef struct val{ int date_1;struct val *next;}*p; void main(void){ char c;for(c=122;c>=97;c--){ p.date=c;p=p->next;} p.next=NULL;} }方法 2:node *p = NULL;node *q = NULL; node *head = (node*)malloc(sizeof(node));head->data = ' ';head->next=NULL; node *first = (node*)malloc(sizeof(node));first->data = 'a';first->next=NULL;head->next = first;p = first; int longth = 'z' - 'b';int i=0;while ( idata = 'b'+i;temp->next=NULL;q=temp; head->next = temp; temp->next=p;p=q;i++;} print(head); 3.可怕的题目终于来了象搜索的输入信息是一个字符串,统计 300 万输入信息中的最热门的前十条,我们每次输入的一个字符串为不超过 255byte,内存使用只有 1G,请描述思想,写出算发(c 语言) ,空间和时间复杂度,4.国内的一些帖吧,如 baidu,有几十万个主题,假设每一个主题都有上亿的跟帖子,怎么样设计这个系统速度最好,请描述思想,写出算发(c 语言) ,空间和时间复杂度, #include string.hmain(void){ char *src="hello,world";char *dest=NULL;dest=(char *)malloc(strlen(src));int len=strlen(str);char *d=dest;char *s=src[len];while(len--!=0)d++=s--;printf("%s",dest);}找出错误!!#include "string.h"#include "stdio.h"#include "malloc.h"main(void){ char *src="hello,world";char *dest=NULL;dest=(char *)malloc(sizeof(char)*(strlen(src)+1));int len=strlen(src);char *d=dest;char *s=src+len-1;while(len--!=0)*d++=*s--;*d='\0';printf("%s",dest);} 1. 简述一个 Linux 驱动程序的主要流程与功能。
2. 请列举一个软件中时间换空间或者空间换时间的例子void swap(int a,int b){int c; c=a;a=b;b=a;}-空优 void swap(int a,int b){a=a+b;b=a-b;a=a-b;}6. 请问一下程序将输出什么结果?char *RetMenory(void){char p[] = “hellow world”;return p;}void Test(void){char *str = NULL;str = RetMemory();printf(str);}RetMenory 执行完毕,p 资源被回收,指向未知地址返回地址,str 的内容应是不可预测的, 打印的应该是 str 的地址 写一个函数,它的原形是 int continumax(char *outputstr,char *intputstr)功能:在字符串中找出连续最长的数字串,并把这个串的长度返回,并把这个最长数字串付给其中一个函数参数 outputstr 所指内存例如:"abcd12345ed125ss123456789"的首地址传给 intputstr 后,函数将返回9,outputstr 所指的值为 123456789int continumax(char *outputstr, char *inputstr){char *in = inputstr, *out = outputstr, *temp, *final;int count = 0, maxlen = 0; while( *in != '\0' ){if( *in > 47 && *in 47 in++ )count++;}elsein++; if( maxlen 0);/*delete the number*/ if(sign using namespace std; void itochar(int num); void itochar(int num){int i = 0;int j ;char stra[10];char strb[10];while ( num ){stra[i++]=num%10+48;num=num/10;}stra[i] = '\0';for( j=0; j >num;itochar(num);return 0;} 前几天面试,有一题想不明白,请教大家!typedef struct { int a:2;int b:2;int c:1;}test; test t;t.a = 1;t.b = 3;t.c = 1; printf("%d",t.a);printf("%d",t.b);printf("%d",t.c); 谢谢!t.a 为 01,输出就是 1t.b 为 11,输出就是-1t.c 为 1,输出也是-13 个都是有符号数 int 嘛。
这是位扩展问题 01111编译器进行符号扩展 求组合数: 求 n 个数(1....n)中 k 个数的组合....如:combination(5,3)要求输出:543,542,541,532,531,521,432,431,421,321,#include int pop(int *);int push(int );void combination(int ,int ); int stack[3]={0};top=-1; int main(){int n,m;printf("Input two numbers:\n");while( (2!=scanf("%d%*c%d",&n,&m)) ){fflush(stdin);printf("Input error! Again:\n");}combination(n,m);printf("\n");}void combination(int m,int n){int temp=m;push(temp);while(1){if(1==temp){if(pop(&temp)&&stack[0]==n) //当栈底元素弹出&&为可能取的最小值,循环退出break;}else if( push(--temp)){printf("%d%d%d ",stack[0],stack[1],stack[2]);//§‥i¤@?pop(}}}int push(int i){stack[++top]=i;if(top=0)return 0;elsereturn 1;} 1、用指针的方法,将字符串“ABCD1234efgh”前后对调显示#include #include #include int main(){char str[] = "ABCD1234efgh";int length = strlen(str);char * p1 = str;char * p2 = str + length - 1;while(p1 double getValue(){double result = 0;int i = 2;while(i 12(删除)345(删除)670(删除) ,如此循环直到最后一个数被删除。
方法 1:数组#include using namespace std;#define null 1000 int main(){int arr[1000];for (int i=0;iusing namespace std;#define null 0struct node{int data;node* next;};int main(){node* head=new node;head->data=0;head->next=null;node* p=head;for(int i=1;idata=i;tmp->next=null;head->next=tmp;head=head->next;}head->next=p;while(p!=p->next){p->next->next=p->next->next->next;p=p->next->next;}coutdata;return 0;}方法 3:通用算法#include #define MAXLINE 1000 //元素个数/*MAXLINE 元素个数a[] 元素数组R[] 指针场suffix 下标index 返回最后的下标序号values 返回最后的下标对应的值start 从第几个开始K 间隔*/int find_n(int a[],int R[],int K,int& index,int& values,int s=0) {int suffix;int front_node,current_node;suffix=0;if(s==0) {current_node=0;front_node=MAXLINE-1;}else { current_node=s;front_node=s-1;}while(R[front_node]!=front_node) {printf("%d\n",a[current_node]);R[front_node]=R[current_node];if(K==1) {current_node=R[front_node];continue;}for(int i=0;i












