笔试题 10

版权声明:本文为博主原创文章,未经博主允许转载。 https://blog.csdn.net/jklinux/article/details/80913388

1 写出以下sizeof(targetX)在64位Linux系统,gcc编译后的执行结果: (注: X=1,2,3,4,5,6)

void func(double target1[1024])
{
    const char *target2 = "hello world\n";
    char *target3 = new char[1024];
    int target4[1024] = {1,2,3,4,5};
}
#pragma pck(push,4)
struct target5
{
    char c;
    double d;
    int i;
};
struct target6
{
    char c;
    target5 t;
    char c2;
};
#pragma pack(pop)

2 输出下面代码的执行结果:

void func(int *a, int & b, int c)
{
    a = (int *)100;
    b = 200;
    c = 300;
}
void main()
{
    int a = 1, b = 2, c = 3;
    func(&a, b, c);
    printf("a = %d, b = %d, c = %d\n", a, b, c);
}

3 指出下面这段代码编译或运行可能出现的问题

const static int EQUIP_COUNT = 8;
int m_level_list[EQUIP_COUNT];
void SetAllEquipLevel(int level, const char *reason)
{
    unsigned short tmp_data[EQUIP_COUNT];
    int *tmp_level_list = (int *)tmp_data;
    for (int i = 0; i < EQUIP_COUNT; i++)
        tmp_level_list[i] = level;
    memcpy(m_level_list, tmp_level_list, EQUIP_COUNT);
    printf("[Log]Set level with reason:%s\n", reason);
}

4 实现一个函数long long Func(int n),要求通过以下检测:

Func(0) == 0;
Func(1) == 1;
Func(n) == Func(n-2) + Func(n-1);
注意:用非递归算法 或者 尾递归算法

5 输出下面代码的执行结果:

const static int MAX_IMG_ID = 40;
int img_flag = 0;
int operate_num = 0;
void ActiveImg(int img_id)
{
    if (0 != (img_flag & (1 << img_id)))
        return;
    img_flag |= 1 << img_id;
    ++operate_num;
}

for (int img_id = 0 ; img_id <= MAX_IMG_ID; ++img_id)
    ActiveImg(img_id);
cout << img_flag << endl; << operate_num << endl;

6 以下为日志文件money_log.txt记录玩家充值元宝日志的其中一行:

[2016-12-12 14:39:34][Money::Charge Succ][user[玩家名字 1064191] charge_gold:160 remain_gold:14555374]

请写一个Shell脚本, 根据以上日志文件,统计2016年第四季度充值最多的玩家排行前20名.

7 实现一个带权的物品无放回抽取程序:
有id为1,2,……, n的n个物品, 它们的权重分别是1,2,…,n. 请设计一个函数:要求”无放回”地抽取x(x<=n)个物品并打印抽到的物品id.


8 简单设计一个跨服服务器架构
注: 跨服玩法,充许原本不在同一个区服的玩家,在活动开启的时间内,可以主动进入到某个统一的场景里。这些玩家突破区服的限制,可以一起合作打副本打BOSS相互切磋竞技等交互玩法。


9 简单设计一个网络传输框架,能实现类似以下效果:

void SendPlayerInfoTo(NetID net_id)
{
    static Protocol::SCPlayerInfo info;
    info.name = "RoleName";
    info.age = 24;
    info.item_list.push_back(1001);
    info.item_list.push_back(5401);
    Network::Instance().Send(net_id, info);
}

猜你喜欢

转载自blog.csdn.net/jklinux/article/details/80913388
今日推荐