《★华为笔试题大全★》由会员分享,可在线阅读,更多相关《★华为笔试题大全★(29页珍藏版)》请在金锄头文库上搜索。
1、华为笔试题大全1 / 29华为笔试题大全1.static有什么用途?(请至少说明两种)1)在函数体,一个被声明为静态的变量在这一函数被调用过程中维持其值不变。2) 在模块内(但在函数体外) ,一个被声明为静态的变量可以被模块内所用函数访问,但不能被模块外其它函数访问。它是一个本地的全局变量。3) 在模块内,一个被声明为静态的函数只可被这一模块内的其它函数调用。那就是,这个函数被限制在声明它的模块的本地范围内使用2.引用与指针有什么区别?1) 引用必须被初始化,指针不必。2) 引用初始化以后不能被改变,指针可以改变所指的对象。3) 不存在指向空值的引用,但是存在指向空值的指针。3.描述实时系统的
2、基本特性在特定时间内完成特定的任务,实时性与可靠性。4.全局变量和局部变量在内存中是否有区别?如果有,是什么区别?全局变量储存在静态数据库,局部变量在堆栈。5.什么是平衡二叉树?左右子树都是平衡二叉树 且左右子树的深度差值的绝对值不大于 1。6.堆栈溢出一般是由什么原因导致的?没有回收垃圾资源。7.什么函数不能声明为虚函数?Constructor(构 造 函 数 )函数不能声明为虚函数。8.冒泡排序算法的时间复杂度是什么?时间复杂度是 O(n2)。9.写出 float x 与“零值”比较的 if语句。if(x-0.000001&x #include #include #include /* 结
3、构体和函数声明 */ typedef struct _node_t int n_num; struct _node_t *next; node_t; node_t *node_t_create(int n); node_t *node_t_get(node_t *pn, int m); /* 功能函数实现 */ /* 华为笔试题大全3 / 29* name: node_t_create * params: * n in 输入要构造的链表的个数 * return: * 返回构造成功的环形单向链表指针 * notes: * 构造节点数量为 n 的环形单向链表 * * author: a.tng 2
4、006/06/14 17:56 */ node_t * node_t_create(int n) node_t *p_ret = NULL; if (0 != n) int n_idx = 1; node_t *p_node = NULL; /* 构造 n 个 node_t */ p_node = (node_t *) malloc(n * sizeof(node_t); if (NULL = p_node) return NULL; else memset(p_node, 0, n * sizeof(node_t); /* 内存空间申请成功 */ p_ret = p_node; for (;
5、 n_idx n_num = n_idx; p_node-next = p_node + 1; p_node = p_node-next; 华为笔试题大全4 / 29p_node-n_num = n; p_node-next = p_ret; return p_ret; /* * name: main * params: * none * return: * int * notes: * main function * * author: a.tng 2006/06/14 18:11 */ int main() int n, m; node_t *p_list, *p_iter; n = 20
6、; m = 6; /* 构造环形单向链表 */ p_list = node_t_create(n); /* josephus 循环取数 */ p_iter = p_list; m %= n; while (p_iter != p_iter-next) int i = 1; /* 取到第 m-1 个节点 */ for (; i next; /* 输出第 m 个节点的值 */ printf(%dn, p_iter-next-n_num); /* 从链表中删除第 m 个节点 */ p_iter-next = p_iter-next-next; p_iter = p_iter-next; printf
7、(%dn, p_iter-n_num); /* 释放申请的空间 */ free(p_list); system(pause); 14.不能做 switch()的参数类型是:switch的参数不能为实型。上海华为的一道关于指针方面的编程题int AnSize,其中隐藏着若干 0,其余非 0整数,写一个函数 int Func(int* A, int nSize),使 A把 0移至后面,非 0整数移至数组前面并保持有序,返回值为原数据中第一个元素为 0的下标。(尽可能不使用辅助空间且考虑效率及异常问题,注释规范且给出设计思路)#include using namespace std;int Func
8、(int* a, int nsize)int i,j,n,num;bool flag=true;i=0;j=nsize-1;while(i aj+1) aj=aj+aj+1; aj+1=aj-aj+1; aj=aj-aj+1; return num;int main()int a12=12,32,4,231,232,0,0,3,123, 23,223,12;int i=Func(a,10);coutnext = NULL;p=h;for(i=0;inext = s;printf(Please input the information of the student: name sex no a
9、ge n);scanf(%s %c %d %d,s-name,s-next = NULL;p = s;printf(Create successful!);return(h);void deletelist(struct stu *s,int a)华为笔试题大全10 / 29struct stu *p;struct stu *s1=s-next;while(s1-age!=a&s1!=NULL)p = s1;s1 = s1-next;if(s1=NULL)printf(The record is not exist.);elsep-next = s-next;printf(Delete suc
10、cessful!);void display(struct stu *s)struct stu *p;p=s-next;while(p!=NULL)printf(%s %c %d %dn,p-name,p-sex,p-no,p-age);p =p-next;int main()struct stu *s;int n,age;华为笔试题大全11 / 29printf(Please input the length of seqlist:n);scanf(%d,s = creatlist(n);display(s);printf(Please input the age:n);scanf(%d,d
11、eletelist(s,age);display(s);return 0;2、实现一个函数,把一个字符串中的字符从小写转为大写。#include stdio.h#include conio.hvoid uppers(char *s,char *us)for(;*s!=0;s+,us+)if(*s=a&*s9) return 2; /*判断正整数是否溢出*/ if (*p-0) (4294967295-(nNumber*10)/应该为 2147483647 华为笔试题大全14 / 29return 4; nNumber = (*p-0) + (nNumber * 10); p+; /*将数字逆序
12、组合,直接抄楼上高手的代码,莫怪,呵呵*/ n = nNumber; while(n) /*判断正整数是否溢出*/ if (n%10) (4294967295-(nTemp*10) /2147483647return 4; nTemp = nTemp*10 + n%10; n /= 10; /*比较逆序数和原序数是否相等*/ if (nNumber != nTemp) return 3; return 0; 方法二 /* - 功能: 判断字符串是否为回文数字 实现: 华为笔试题大全15 / 29先得到字符串的长度,再依次比较字符串的对应位字符是否相同 输入: char *s:待判断的字符串 输
13、出: 无 返回: 0:正确;1:待判断的字符串为空;2:待判断的字符串不为数字; 3:字符串不为回文数字 - */ unsigned IsSymmetry_2(char *s) char *p = s; int nLen = 0; int i = 0; /*判断输入是否为空*/ if (*s = 0) return 1; /*得到字符串长度*/ while (*p != 0) /*判断字符是否为数字*/ if (*p9) return 2; nLen+; /长度不包括0p+; /*长度不为奇数,不为回文数字*/ 华为笔试题大全16 / 29if (nLen%2 = 0) return 3; /
14、*长度为 1,即为回文数字*/ if (nLen = 1) return 0; /*依次比较对应字符是否相同*/ p = s; i = nLen/2 - 1; while (i) if (*(p+i) != *(p+nLen-i-1) return 3; i- -; return 0; 求 22000的所有素数.有足够的内存,要求尽量快#include#include #define N 2001void main()int i,j,line,aN;for(i=1;inext;while(q!=NULL)r=q-next;q-next=p;p=q;q=r;head-next=NULL;head=p;return head;华为笔试题大全20 / 293.将二叉树的两个孩子换位置,即左变右,右变左。不能用递归(变态!)华为笔试题:2007.03.31 华为笔试题之一二给大家说几个:(感觉华为不过如此,虽然我的分不高,因为很多题我做给他实在是侮辱我的智商)1。大意如下:38 头牛中选出 3头跑得最快的,使用一个每次只能供 6头比赛的场地,要求用最快的方法。 (我给一个最傻瓜的答案,因为我发