当前位置:首页 > C语言面试题
if( n= =1 ) return true; if( n= =2 )
return a[n-1] >= a[n-2];
return fun( a,n-1) && ( a[n-1] >= a[n-2] ); }
4、编写算法,从10亿个浮点数当中,选出其中最大的10000个。 用外部排序,在《数据结构》书上有
《计算方法导论》在找到第n大的数的算法上加工 5、编写一unix程序,防止僵尸进程的出现.
同学的4道面试题,应聘的职位是搜索引擎工程师,后两道超级难,(希望大家多给一些算发)
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 ( i<=longth ) {
node *temp = (node*)malloc(sizeof(node)); temp->data = '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.h main(void)
{ char *src=\ 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(\ }
找出错误!!
#include \ #include \ #include \ main(void) {
char *src=\ 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(\ }
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所指内存。例如:\的首地址传给intputstr后,函数将返回
9,outputstr所指的值为123456789
int continumax(char *outputstr, char *inputstr) {
char *in = inputstr, *out = outputstr, *temp, *final; int count = 0, maxlen = 0; while( *in != '\\0' ) {
if( *in > 47 && *in < 58 ) {
for(temp = in; *in > 47 && *in < 58 ; in++ ) count++; } else in++;
if( maxlen < count ) {
maxlen = count; count = 0; final = temp; } }
for(int i = 0; i < maxlen; i++) {
*out = *final; out++; final++; }
*out = '\\0'; return maxlen; }
不用库函数,用C语言实现将一整型数字转化为字符串 方法1:
int getlen(char *s){ int n;
for(n = 0; *s != '\\0'; s++) n++; return n; }
void reverse(char s[]) {
int c,i,j;
for(i = 0,j = getlen(s) - 1; i < j; i++,j--){ c = s[i]; s[i] = s[j]; s[j] = c; } }
void itoa(int n,char s[]) {
int i,sign;
if((sign = n) < 0) n = -n; i = 0;
do{/*以反序生成数字*/
s[i++] = n + '0';/*get next number*/ }while((n /= 10) > 0);/*delete the number*/ if(sign < 0) s[i++] = '-'; s[i] = '\\0'; reverse(s); }
方法2:
#include
int i = 0; int j ;
char stra[10]; char strb[10]; while ( num ) {
stra[i++]=num+48; num=num/10; }
stra[i] = '\\0';
for( j=0; j < i; j++) {
strb[j] = stra[i-j-1]; }
strb[j] = '\\0';
cout< int main() { int num; cin>>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(\ printf(\ printf(\ 谢谢!
共分享92篇相关文档