百度东大笔试题

13 views
Skip to first unread message

Thronds

unread,
Oct 21, 2008, 12:51:50 AM10/21/08
to TopLanguage
1. 某计算机系统只有以下原子操作:
赋值
+1运算
循环 只能是固定次数的循环
只操作0和正整数
不会溢出
用伪代码实现加法,减法,乘法和除法运算。

2.找出下面程序的错误,如何修正。
#include <vector>
#include <iostream>
#include <string>
#include <fstream>

using namespace std;
class Test
{
public:
string s;
};
int main()
{
Test *t= new Test[3];
ofstream output("file",ofstream::binary);
t[0].s="hello";
t[1].s="world";
t[2].s="!";
output.write((char* )t,3*sizeof(Test));
output.close();
delete[] t;
ifstream input("file",ifstream::binary);
Test in[3];
input.read((char* )in,3*sizeof(Test));
input.close();
cout<<in[0].s<<in[1].s<<in[2].s<<endl;
return 0;
}

(1)找出程序中的错误,如何修正
(2)stl中string的内存管理方式
(3)用C实现一个可变长字符串,要求方便高效。

3.大型系统多采用数据库存储数据,但访问量很大,所以要用cache,又因为数据规模也很大,所以用分布式管理。有一个查询语句 select
pid uid content from ltb where fid = FID & power = POWER order by pid.查
询的差别就是fid和power的不同。根据上面信息优化上面的查询语句。
现在请设计一个方案用来实现下面两个目标:
1).可实现查询,更新命令
2).能够高效地查询更新
请给出:
1).核心的数据结构和算法
2).描述存储方案
3).给出一个查询和更新过程。

啊拉飞仔

unread,
Oct 21, 2008, 4:31:02 AM10/21/08
to TopLanguage
水木上给的 第一题 的办法。

发信人: riverlights (ll), 信区: Baidu
标 题: Re: 听来的百度面试题 (转载)
发信站: 水木社区 (Tue Oct 21 13:53:14 2008), 站内

sub(a, b)
{
c = a;
loop(b)
{
i = 0;
j = 0;
loop(a)
{
i = j;
j = j + 1;
}
c = i;
}
return c;
}

div(a, b)
{
c=a;
d=0;
loop(a)
{
c = sub(c, b);
i = 0;
loop(c) i=1;
d = d + i;
}
return d;

啊拉飞仔

unread,
Oct 21, 2008, 4:42:58 AM10/21/08
to TopLanguage
这个其实偷奸取巧了,它默认了 loop 能处理 c 为负数的情况,

结果loop还是要能判断小于0时该怎么办。。。
> > 3).给出一个查询和更新过程。- 隐藏被引用文字 -
>
> - 显示引用的文字 -

Arrix

unread,
Oct 21, 2008, 7:03:21 AM10/21/08
to pon...@googlegroups.com
c是通过上面定义的sub得到,不会为负。

2008/10/21 啊拉飞仔 <jjymh...@gmail.com>

这个其实偷奸取巧了,它默认了 loop 能处理 c 为负数的情况,

结果loop还是要能判断小于0时该怎么办。。。
--
Arrix

啊拉飞仔

unread,
Oct 21, 2008, 8:23:53 AM10/21/08
to TopLanguage
减法那不步,应该有问题。

On 10月21日, 下午7时03分, Arrix <arrixz...@gmail.com> wrote:
> c是通过上面定义的sub得到,不会为负。
>
> 2008/10/21 啊拉飞仔 <jjymhkx0...@gmail.com>

郜小亮

unread,
Oct 24, 2008, 3:56:43 AM10/24/08
to pon...@googlegroups.com
没有发现有什么问题啊!!

2008/10/21 Thronds <thr...@gmail.com>

啊拉飞仔

unread,
Oct 24, 2008, 5:59:33 AM10/24/08
to TopLanguage
。。。loop(a) 因该是 loop(c) 吧。。。

On 10月24日, 下午3时56分, "郜小亮" <venus....@gmail.com> wrote:
> 没有发现有什么问题啊!!
>
> 2008/10/21 Thronds <thro...@gmail.com>
> > (3)用C实现一个可变长字符串,要求方便高效。- 隐藏被引用文字 -
>
> - 显示引用的文字 -
Reply all
Reply to author
Forward
0 new messages