Strict Standards: Non-static method BBCode::decode_php() should not be called statically in /var/www/vhosts/westca.com/httpdocs/includes/nbbcode.php on line 967

Strict Standards: Non-static method BBCode::decode_php() should not be called statically in /var/www/vhosts/westca.com/httpdocs/includes/nbbcode.php on line 967

Strict Standards: Non-static method BBCode::decode_php() should not be called statically in /var/www/vhosts/westca.com/httpdocs/includes/nbbcode.php on line 967

Strict Standards: Non-static method BBCode::decode_php() should not be called statically in /var/www/vhosts/westca.com/httpdocs/includes/nbbcode.php on line 967

Strict Standards: Non-static method BBCode::decode_php() should not be called statically in /var/www/vhosts/westca.com/httpdocs/includes/nbbcode.php on line 967

Strict Standards: Non-static method BBCode::decode_php() should not be called statically in /var/www/vhosts/westca.com/httpdocs/includes/nbbcode.php on line 967

Strict Standards: Non-static method BBCode::decode_php() should not be called statically in /var/www/vhosts/westca.com/httpdocs/includes/nbbcode.php on line 967
每周一题 -- Nov 17 | IT人生 | 移民生活北美论坛 | 加西网 (温哥华门户)
| 广告联系 | 繁体版 | 手机版 | 微信 | 微博 | 搜索:
欢迎您 游客 | 登录 | 免费注册 | 忘记了密码 | 社交账号注册或登录

首页

新闻资讯

论坛

温哥华地产

大温餐馆点评

温哥华汽车

温哥华教育

黄页/二手

旅游
搜索:  

 论坛通告:  请不要上传第三方有版权的照片,请尊重版权,谢谢   转载新闻请务必注明出处,这些媒体请不要转,谢谢   批评商家需要注意  
 个人空间: reddragon | 罗蓬特机器人 | 乱想 | XY | 客观中立而实事求是,唯服理据而杜绝辱骂 | 猪头看世界 | 静观云卷云舒 | 细雨飘渺 | 异乡的世界 | 湖里湖涂 | 五木森林 | 花随风 | lxls | rxmei | Notme | 顾晓军 | Amy Yi | 53757645468 | 逸言堂 | 北极熊要去北极老家
 最新求助: 请问谁知道哪里有卖理发的电动推子?   忽然有个疑问:战争时期,加拿大拿PR卡未入籍的永久居民会被强制服兵役吗?   这个银条   如何修改会员名?
 论坛转跳:
     发帖回帖获取加西镑, 兑换精彩礼物

论坛首页 -> IT人生

每周一题 -- Nov 17 (发表于17年前)

分页: 1, 2, 3  下一页  



回复主题  图片幻灯展示  增添帖子到书签中  给帖子中的发贴者批量赠送献花或者花篮    |##| -> |=|        发表新主题
阅读上一个主题 :: 阅读下一个主题  
作者 正文
杜鲁门
(只看此人)




文章 时间: 2008-11-17 15:46 引用回复
一道面试题,题目有点长

===[ Introduction ]============================================================

The enclosed code is some basic code for managing path-node and Power-Up
objects in a 3D Map. A very simple power-up heirarchy is in place but is
far from complete.

As I'm sure you know, path-nodes are used by AI agents to navigate through a
map. A typical "real" map would contain upwards of a thousand PathNodes, but
we've included a simple graph of 8 nodes. A pictoral representation of the
graph is shown in Graph.png and the data has been entered in Main.cpp.

The test has been broken up into three small parts. The entire thing should
take no-more than a few hours (an evening, tops), but take your time. Please
keep a rough idea of how long you spent at it, though -- if you spent more
time and did cooler stuff, that's all good.

===[ Part 1 ]==================================================================

Find as many bugs with the existing code as you can. There are several subtle
but common errors throughout the code. It compiles, and runs, but would not
stand up to production use.

For bonus marks, add a few statements here-and-there to make the code more
quick to detect errors.

You can impose any reasonable restrictions on how the functions can be used
and abused. Halting the program on error illegal input is acceptable in most
cases, but use your judgement for deciding when it isn't appropriate.

===[ Part 2 ]==================================================================

Implement the "findPowerUp" function sketched out in Main.cpp. It is to find a
path through the graph of PathNodes to the nearest PowerUp of the given mType.
Return NULL for no-path, or return an allocated array containing the path as
shown in the function skeleton.

Please briefly describe the algorithm you chose and why you chose it in a
comment block at the top of the function.

===[ Part 3 ]==================================================================

Fill in the Armor and Weapon classes. Add members and methods that you think
would be useful for these kinds of objects. What you add is totally up to you;
it's more meant to show your personal coding style and how you think about
what kind of functionality you'd want to add to the game.

This part is very subjective, so don't worry about it -- there is no wrong
answer.

Vertex.h
PHP源代码:

#ifndef VERTEX_H
#define VERTEX_H

struct Vertex
{
    
Vertex()
    {
    }

    
Vertex(float iXfloat iYfloat iZ) :
        
x(iX),
        
y(iY),
        
z(iZ)
    {
    }

    
float xyz;
};

#endif // VERTEX_H



PowerUp.h
PHP源代码:

#ifndef POWER_UP_H
#define POWER_UP_H

#include "Vertex.h"
#include <string.h>

class PowerUp
{
public:
    
PowerUp(const charnameVertex position)
    {
        
mPosition position;
        
mName = new char [strlen(name)];
        
strcpy(mNamename);
    }

    ~
PowerUp()
    {
        
delete mName;
    }

    
enum PowerUpType
    
{
        
WEAPON,
        
ARMOUR
        
HEALTH
    
};

    
PowerUpType getPowerUpType() const
    {
        return(
mType);
    };

    const 
VertexGetPosition() const
    {
        return(
mPosition);
    }

protected:
    
Vertex      mPosition;
    
PowerUpType mType;
    
char*       mName;
};

#endif // POWER_UP_H



PathNode.h
PHP源代码:


Weapon.h
PHP源代码:

#ifndef WEAPON_H
#define WEAPON_H

#include "PowerUp.h"

class Weapon : public PowerUp
{
public:
    
Weapon(const charnameVertex position) :
        
PowerUp(nameposition)
    {
        
mType WEAPON;
    }
};

#endif // WEAPON_H



Health.h
PHP源代码:

#ifndef HEALTH_H
#define HEALTH_H

#include "PowerUp.h"

class Health : public PowerUp
{
public:
    
Health(const charnameVertex position) :
        
PowerUp(nameposition)
    {
        
mType HEALTH;
    }
    
protected:
    
float healing;
};

#endif // HEALTH_H



Armor.h
PHP源代码:

#ifndef ARMOUR_H
#define ARMOUR_H

#include "PowerUp.h"

#include <stddef.h>
#include <string.h>

class Armour : public PowerUp
{
public:
    
Armour(const charname, const Vertexposition) :
        
PowerUp(nameposition)
    {
        
mType ARMOUR;
        
mClanTag NULL;
    }

    ~
Armour()
    {
        
delete mClanTag;
    }

    const 
chargetClanTag() const
    {
        return(
mClanTag);
    }

    
void setClanTag(charn)
    {
        
delete mClanTag;
        
mClanTag = new char[strlen(n)];
        
strcpy(mClanTagn);
    }

protected:
    
charmClanTag;
};

#endif // ARMOUR_H



Main.cpp
PHP源代码:



Graph.png

 
花篮 (7)
分享
楼主 | 电梯直达
阅读会员资料 发送站内短信 主题 User photo gallery 礼物  
webdriver
(只看此人)




文章 时间: 2008-11-17 15:52 引用回复
像是某家游戏公司的面试题
 
花篮
分享
_________________
There is no wisdom tree; nor a stand of a mirror bright, Since all is void, where can the dust alight?
沙发 | 返回顶端
阅读会员资料 发送站内短信 主题 User photo gallery 礼物  
webdriver
(只看此人)



文章 时间: 2008-11-17 16:16 引用回复
而且比较复杂,如果不让上机操作的话,要在半个小时内搞清楚关系,算是高手了。
 
花篮
分享
_________________
There is no wisdom tree; nor a stand of a mirror bright, Since all is void, where can the dust alight?
板凳 | 返回顶端
阅读会员资料 发送站内短信 主题 User photo gallery 礼物  
杜鲁门
(只看此人)



文章 时间: 2008-11-17 16:20 引用回复
课外作业 几个小时之内完成都可以 答卷应是可编译运行的
 
花篮
分享
地板 | 返回顶端
阅读会员资料 发送站内短信 主题 User photo gallery 礼物  
7thGuest
(只看此人)



文章 时间: 2008-11-17 16:23 引用回复
they allow you to use a compiler in interview? they are quite kind big_happy.gif
 
花篮
分享
_________________
烈焰空烧吾秘授
5 楼 | 返回顶端
阅读会员资料 发送站内短信 主题 User photo gallery 礼物  
webdriver
(只看此人)



文章 时间: 2008-11-17 16:28 引用回复
杜鲁门 写道:
课外作业 几个小时之内完成都可以 答卷应是可编译运行的


这样简单多了

1) 主要问题是constructor,destructor的问题,尤其是stl vector,用push back的对象一定要实现copy constructor
2) 头文件包含问题,如果没有采用pre-compile header选项,其中几个文件无法编译
3) 直接引用下标而不做下标检查,太容易出错了(core dump)
4) 有些变量未初始化就用,dotNet检查严格多了
5) 数组越界问题
 
花篮
分享
_________________
There is no wisdom tree; nor a stand of a mirror bright, Since all is void, where can the dust alight?


上一次由webdriver于2008-11-17 16:38修改,总共修改了1次
6 楼 | 返回顶端
阅读会员资料 发送站内短信 主题 User photo gallery 礼物  
SARS
(只看此人)



文章 时间: 2008-11-17 16:30 引用回复
看题都要看半小时 dqvoar.gif

先挑几个显而易见的错误:

1、所有 new char [strlen(name)]语句的中括号内应该再+1

2、main中一开始在堆上创建的那一大堆对象,后来又放到两个vector中去了。但退出的时候没见着删除(或许是俺老眼昏花看漏了? big_dizzy.gif

3、PowerUp::~PowerUp()应该是虚函数,否则即便改正了错误2,它的那些乱七八糟的子类对象也无法删除(搞不好还会crash)

4、delete字符串指针之前都检查一下空指针系不系更安全一些?

有空再继续找......
 
花篮
分享
_________________


你好,外星人,我们有猫~
7 楼 | 返回顶端
阅读会员资料 发送站内短信 主题 User photo gallery 礼物  
7thGuest
(只看此人)



文章 时间: 2008-11-17 16:30 引用回复
here is what I come up with with first sight big_happy.gif
1. strlen doesn't include the tail 0. +1 please
2. anytime use new[], use delete[]
3. destructor of PathNode is not implemented, I don't know how it can compile
4. pathnode and powerup and its inheritance, non of them implement copy construct, when they are put into stl container, memory leak/stomping everywhere.
5. one of the Vector construtor doesn't initialize its member, looking for trouble of determinism
6. if you want, you can always asset(name), but not a big deal
7. not quite sure if erase(vector.end()) is legal or not, personally, I am not a big fan of stl.
 
花篮
分享
_________________
烈焰空烧吾秘授
8 楼 | 返回顶端
阅读会员资料 发送站内短信 主题 User photo gallery 礼物  
7thGuest
(只看此人)



文章 时间: 2008-11-17 16:31 引用回复
delete null is 100% legal.

no need to check
 
花篮
分享
_________________
烈焰空烧吾秘授
9 楼 | 返回顶端
阅读会员资料 发送站内短信 主题 User photo gallery 礼物  
7thGuest
(只看此人)



文章 时间: 2008-11-17 16:42 引用回复
SARS 写道:
3、PowerUp::~PowerUp()应该是虚函数,否则即便改正了错误2,它的那些乱七八糟的子类对象也无法删除(搞不好还会crash)


right, forgot about this, together with the other 2 member functions
 
花篮
分享
_________________
烈焰空烧吾秘授


上一次由7thGuest于2008-11-17 16:42修改,总共修改了1次
10 楼 | 返回顶端
阅读会员资料 发送站内短信 主题 User photo gallery 礼物  
 
回复主题     |##| -> |=|     论坛首页 -> IT人生 所有的时间均为 美国太平洋时间
1页,共3 分页: 1, 2, 3  下一页  


注:
  • 以上论坛所有发言仅代表发帖者个人观点, 并不代表本站观点或立场, 加西网对此不负任何责任。
  • 投资理财及买房卖房版面的帖子不构成投资建议。投资有风险,责任请自负
  • 对二手买卖中的虚假信息,买卖中的纠纷等均与本站无关。
  • 黄页热门商家 免费个人广告
    发布商业广告

    不能在本论坛发表新主题
    不能在本论坛回复主题
    不能在本论坛编辑自己的文章
    不能在本论坛删除自己的文章
    不能在本论坛发表投票
    不能在这个论坛添加附件
    可以在这个论坛下载文件

    论坛转跳: 

    杜鲁门, webdriver, webdriver, 杜鲁门, 7thGuest, webdriver, SARS, 7thGuest, 7thGuest, 7thGuest
    潜力帖子 精华帖子 热门帖子
    尹科就是个彻头彻尾的骗子
    揭开财经新闻界的“伪君子”面纱—...
    姜维平就是个黑中介,满嘴谎话
    好消息来了:床铺荣获和平奖了
    当年的全家福
    本宫好不容易练完央院钢琴9级德彪西...
    任素汐最新电视剧,在多伦多拍的!
    哇,中华料理,包容性太强了吧
    高尚的汉语被谁牵头市井化
    完犊子了!小红书被台湾封了!
    世界杯分组出来了
    货币的平权,中本聪难逃宿命
    黄MAGA打Covid疫苗了么
    美《国家安全战略》出炉!遏阻台湾...
    路透:五角大厦要求欧洲2027前主导...
    迈阿密(三)Key West
    一夜消失! 加拿大这家华人超市突然...
    迈阿密(二)大沼泽地 维资卡亚 海...
    迈阿密(一)南沙滩 小哈瓦那 温伍...
    加拿大全国各地兑换纪念【无名烈士...
    2025纪念无名烈士加拿大2元流通硬币
    自藏求精!
    西岸快线30周年纪念品
    天津深度游(二)
    天津深度游
    mint十月新币 (十一月新币从25楼开始)
    魁北克 水晶瀑布 加国航拍
    舌尖上的预制菜!
    游了一下多伦多(三)多伦多群岛 湖...
    游了一下多伦多(二)多大 省议会 ...
    超级重磅!加拿大要进口中国电动车!
    皮尔今天在温哥华 - 蓝色wave - 保...
    几分钟前,中国强硬反击,征34+50,...
    曼谷高楼直接倒了
    我说我希望特朗普赢,老公气得眼睛...
    知乎?加西网上为什么有老流氓刘厅...
    明明有能力统台,大陆为何迟迟不动手?
    貌似ndp稍占上风。。。。。
    今天是感恩节,跟大家道个别,以后...
    咱最后还是投了ndp
    生平第一次被偷车了
    中国会不会武统台湾
    突发:台湾队战胜中国队奥运夺冠,...
    温哥华房姐出事了
    有在看总统辩论的吗?

    最新新闻 热门新闻 热评新闻
    四川有个尴尬的功勋县,藏着一个重要的秘密
    在北京,海淀区北三环的房价让人震惊
    默认金正恩这权利 中国删除重要条款
    刚刚!BC北边发生7级强震 震感强烈
    范玮琪"僵脸"大变 网惊认不出:嘴歪到耳根
    紧张!渥太华开始考虑"魁北克公投"的可能性
    研究:早餐这杯常见果汁护心又延寿
    公安部门户网站帐号直播卖鞋 全网群嘲
    加国男子中1500万大奖 将匿名捐款 不想改变生活
    加拿大超市省钱指南:这样买最划算
    川普扔"核弹"!华盛顿出台史上最危险文件
    美景都没有了?谁还想移民来温哥华
    被骂下架的美团公益广告,忽略了最基本的一点
    年代剧《生万物》天津卫视开播(图
    熊出没民宅!大块头窝进加州屋底10天不走
    哈马斯高级领导人:拒绝对加沙地带进行外部托管
    2026民众党怎么突破?柯文哲已经开始布局
    特朗普将废"出生公民权",美最高法院决定合宪审查
    裁员提速!三名初级会计师8小时的活AI1小时搞定
    美客机急坠迫降 或由游荡数百万年的宇宙射线造成
    生育18个孩子,俄"超级母亲"离世,年仅59岁
    早上总想睡?5大清醒秘诀 比咖啡因更有效
    美新生儿不用接种乙肝疫苗了?仍是中国防控手段
    北京批斗日本,中国民众"不抵制日货"原因曝
    去中国看看 英诺奖得主感慨:我们的大学像第三世界
    美国安报告1变动让中国不开心!习肯定会提出
    英国被曝考虑向乌移交750亿元俄被冻结资产!俄罗斯警告…
    落地凤凰不如鸡!陈法蓉蔡少芬近照流出,个矮...
    林晓霖:她是林豆豆同父异母的姐姐,一生坎坷
    谷歌憋了十年的大招,让英伟达好日子到头了?
    被国内吹上天的"伪豪车",在国外却没人搭理
    太惨了! 卑诗一户人家3年被撞4次
    官宣喜讯刚1个月 关晓彤亮新身份 鹿晗赚了
    网友推算 香港大火实际罹难人数1500人以上
    美将领承认:被美军二次打击的贩毒船并非驶向美国
    穷疯了?温哥华市政想收"知情费"
    驻日美军士兵猥亵未成年少女 日本检方不予起诉
    华裔女演员状告西捷 称遭空乘霸凌
    中国移民年入$180亿!真实身份可怕,8保镖跟随
    2026民众党怎么突破?柯文哲已经开始布局
    特朗普将废"出生公民权",美最高法院决定合宪审查
    裁员提速!三名初级会计师8小时的活AI1小时搞定
    美客机急坠迫降 或由游荡数百万年的宇宙射线造成
    生育18个孩子,俄"超级母亲"离世,年仅59岁
    早上总想睡?5大清醒秘诀 比咖啡因更有效

    更多方式阅读论坛:

    Android: 加西网
    [下载]

    Android: 温哥华论坛
    [下载]

    PDA版本: 论坛

    加西网微信

    加西网微博


    Powered by phpBB 2.0.8
    Terms & Conditions    Privacy Policy    Political ADs    Activities Agreement    Contact Us    Sitemap    

    加西网为北美中文网传媒集团旗下网站

    页面生成: 0.1334 秒 and 7 DB Queries in 0.0020 秒