百度2015网页搜索部笔试题
1.
1.1 在 little-endian 的系统中,下面一段代码输出什么?
union Number{
int i;
struct{
short a;
short b;
}num;
};
void main()
{
Number number;
number.i = 0x102;
printf("%d,%d\n", number.num.a, number.num.b);
}
1.2 请问运行 Test 函数会有什么样的结果?
a) void Fun(char *p){
p = (char*)malloc(100);
}
void Test(){
char *str = NULL;
Fun(str);
strcpy(str, "hello world");
printf(str);
}
b) char* Fun(){
char *p = "hello world";
return p;
}
void Test(){
char *str = NULL;
str = Fun();
printf(str);
}
2. Java 继承题,略。
4. 实现一个函数,从数组中删除值为 value 的元素。要求不开辟新的存储空间。
5. 实现一个函数,给定一个字符串 s 和一个词典 dict ,判断字符串是否能够分割成词典中存在的一个个单词。比方说: s= " 百度一下 " , dict=[ " 百 度 ", " 一下 "] ,返回 true ,因为 " 百度一下 " 能够被分割成 " 百度 " 、 " 一下 " 。
6. 一个只含有 0 — n-1 且不重复的数组,要求只能够和 0 交换,实现升序排列。
7. 两个一模一样的碗,一号碗有 30 颗水果糖和 10 颗巧克力糖,二号碗有水果糖和巧克力糖各 20 颗。现在随机选择一个碗,从中摸出一颗糖,发现是水果糖,求这颗水果糖来自 1 号碗的概率,给出计算过程。
查看8道真题和解析
