cais 发表于 14-4-2013 23:17:53

又看到一个c++的职位

同学们不要再说没有C++的职位哦。
http://careers.stackoverflow.com/jobs/33141/software-engineer-mobile-robotics-c-plus-plus-linux-marathon-targets
看起来做的东西挺有趣的。
还出了一道题呢。
In order to increase your chances of being short-listed, please submit with your application a function which returns the set of all integers between x and y inclusive (for positive x and y), which are multiples of 4 or 6. For example: x=3, y=12 -> { 4, 6, 8, 12 }.
这题我估计如果是面试碰到的话,肯定要问到你不能用除法,乘法为止。

tristone 发表于 15-4-2013 07:23:38

原帖由 cais 于 14-4-2013 23:17 发表 http://www.freeoz.org/ibbs/images/common/back.gif
同学们不要再说没有C++的职位哦。
http://careers.stackoverflow.com/jobs/33141/software-engineer-mobile-robotics-c-plus-plus-linux-marathon-targets
看起来做的东西挺有趣的。
还出了一道题呢。
In order...

这个看起来像国防的职位啊,很可能要求citizenship呢。

DDD888 发表于 15-4-2013 07:23:47

原帖由 cais 于 14-4-2013 23:17 发表 http://www.freeoz.org/ibbs/images/common/back.gif
肯定要问到你不能用除法,乘法为止

Plus is faster than multiple and division, just +4,+6 should be fine:lol

planetkeeper 发表于 15-4-2013 10:13:36

谢谢cais兄
晚上回家投

惭愧啊
两个月过去了
我还是没找好下家

cais 发表于 16-4-2013 01:19:48

原帖由 DDD888 于 15-4-2013 07:23 发表 http://www.freeoz.org/ibbs/images/common/back.gif


Plus is faster than multiple and division, just +4,+6 should be fine:lol
由于要的是set,4跟6的倍数有重复。我的想法是弄一个array 这样每隔12这样算。一开始上来可能要先用除法算一次x mod 12,把开头不整齐的先算出来,接下来就是直接不停的按array里面的数加,加到y为止。

planetkeeper 发表于 16-4-2013 06:58:07

这个题目其实蛮简单的,只要两个数列一起递加,每次选出最小的数
一次循环只用+就搞定

cais 发表于 16-4-2013 22:11:17

也对。你快点去申请吧

DDD888 发表于 17-4-2013 08:32:13

Just for fun

This is my brief answer.

#include "stdafx.h"

#include <iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
    int x = 3;
    int y = 12;

    int sequence1 = 4;
    int sequence2 = 6;
    while (true)
    {
      int iMin;
                if (sequence1 < sequence2)
                {
                        iMin = sequence1;
            sequence1 += 4;
                }
                else if (sequence1 == sequence2)
                {
                        iMin = sequence1;
            sequence1 += 4;
            sequence2 += 6;
                }
                else
                {
                        iMin = sequence2;
            sequence2 += 6;
                }

      if (iMin > y)
      {
            break;
      }

      cout << iMin << '\n';
    }

        cin.get();

        return 0;
}

planetkeeper 发表于 17-4-2013 13:01:50

原帖由 cais 于 16-4-2013 22:11 发表 http://www.freeoz.org/ibbs/images/common/back.gif
也对。你快点去申请吧
呵呵,你这个帖子发出来当天我就去申请了:loveliness:

DDD888 发表于 17-4-2013 15:03:25

原帖由 planetkeeper 于 17-4-2013 13:01 发表 http://www.freeoz.org/ibbs/images/common/back.gif

呵呵,你这个帖子发出来当天我就去申请了:loveliness:

All the best :victory:

cais 发表于 19-4-2013 18:14:12

原帖由 DDD888 于 17-4-2013 08:32 发表 http://freeoz.org/ibbs/images/common/back.gif
Just for fun

This is my brief answer.

#include "stdafx.h"

#include
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
    int x = 3;
    int y = 12;

    int sequence1 = 4; ...
x怎么没有用到啊?

DDD888 发表于 20-4-2013 07:23:58

原帖由 cais 于 19-4-2013 18:14 发表 http://www.freeoz.org/ibbs/images/common/back.gif

x怎么没有用到啊?

It is just a demo. No need to be 100% correct :lol

cais 发表于 20-4-2013 11:52:54

原帖由 DDD888 于 20-4-2013 07:23 发表 http://www.freeoz.org/ibbs/images/common/back.gif


It is just a demo. No need to be 100% correct :lol
怎么可以这样呢。这个关系到你要不要用乘法啊。
而且compile的时候,有提示x没被用到的。
你这样是拿不到面试的哦。;P

DDD888 发表于 20-4-2013 16:01:27

原帖由 cais 于 20-4-2013 11:52 发表 http://www.freeoz.org/ibbs/images/common/back.gif

怎么可以这样呢。这个关系到你要不要用乘法啊。
而且compile的时候,有提示x没被用到的。
你这样是拿不到面试的哦。;P

The code is compiled under Visual Studio in Windows and I thought that they are doing linux stuff. So the code is only for demo purpose. :lol

ricowang 发表于 20-4-2013 16:20:20

原帖由 DDD888 于 17-4-2013 06:32 发表 http://www.freeoz.org/ibbs/images/common/back.gif
Just for fun

This is my brief answer.

#include "stdafx.h"

#include
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
    int x = 3;
    int y = 12;

    int sequence1 = 4; ...

你彻底错了,
要求是function,其次返回set,不看你里面的内容,最基本的都满足啊

#include <set>
typedef unsigned int UINT;

void get_multiples(UINTx, UINT y, std:set<UINT> & mset)
{
UINT base1 = 4, base2 = 6;
mset.clear();

if(x > y)
{
    UINT z;
    z = x;
    x = y;
    y = x;
}

    for(UINT i = x; i <= y; i++)
    {
      if( !(i % base1) )
      {
      mset.insert(i);
      continue;
      }
      
      if( !(i % base2) )
      {
      mset.insert(i);
      }
    }
}

[ 本帖最后由 ricowang 于 20-4-2013 14:25 编辑 ]

DDD888 发表于 20-4-2013 18:05:21

原帖由 ricowang 于 20-4-2013 16:20 发表 http://www.freeoz.org/ibbs/images/common/back.gif


你彻底错了,
要求是function,其次返回set,不看你里面的内容,最基本的都满足啊

You miss the point. I don't care about function or set whatever. My demo code just show plus operation can do the job without expensive multiply, division, mod operation.

planetkeeper 发表于 20-4-2013 18:26:22

原帖由 ricowang 于 20-4-2013 16:20 发表 http://www.freeoz.org/ibbs/images/common/back.gif


你彻底错了,
要求是function,其次返回set,不看你里面的内容,最基本的都满足啊

#include
typedef unsigned int UINT;

void get_multiples(UINTx, UINT y, std:set & mset)
{
UINT base1 = 4, ba ...
你这code的效率。。。。

咱华人coder不能比土澳还效率低啊

ricowang 发表于 20-4-2013 21:35:08

原帖由 planetkeeper 于 20-4-2013 16:26 发表 http://www.freeoz.org/ibbs/images/common/back.gif

你这code的效率。。。。

咱华人coder不能比土澳还效率低啊

效率根本不是问题,除非被明确提及
在澳洲人值钱还是机器值钱?
就像前面那个DD888那样,写个以为很节约的程序,实际上呢,还是个错误的
如果你是老板你选哪个?呵呵

[ 本帖最后由 ricowang 于 20-4-2013 19:44 编辑 ]

ricowang 发表于 20-4-2013 21:56:42

原帖由 DDD888 于 20-4-2013 16:05 发表 http://www.freeoz.org/ibbs/images/common/back.gif


You miss the point. I don't care about function or set whatever. My demo code just show plus operation can do the job without expensive multiply, division, mod operation.

不使用除法或者是modulo运算,你是写不出来的
你的程序本身就是错误的,连x都没有用到,不值一提

planetkeeper 发表于 20-4-2013 23:38:09

DDD888的思路是对的,有很多细节没有cover到了
这题当然不用mod或除法。。。

planetkeeper 发表于 20-4-2013 23:40:55

在什么地方都是会设计架构,优化算法的人值钱
我们首先是coder,然后才是目前在澳洲工作的coder

首先要以coder的高标准要求自己,尤其在澳洲技术更新慢的环境下,这样才不会被抛离

cais 发表于 21-4-2013 00:19:54

这个题目虽然说要the set of xxx,但是我觉得并不需要返回一个std::set或者一个set class。只需要确保返回的数里面没有重复就行了。
ddd888的做法,只需要在考虑要不要算上iMin时加上一个判断 if (iMin>=x) 就好了。他自己也说了是顺便写写。相信真要他申请,肯定要跑几遍测试几下的。
我觉得这个东西,想通过你的解答为申请加分,应该不能满足于答案的正确性。要在思路上要些亮点。比如算法上效率高一点。加点其它花俏一点的东西。
我也贴一个:
实在想不到怎么样比较简单地返回一个array,就用了vector。
另外,就着习惯,加了点test。实在没用过cppunit之类的,就弄了个简单的assert。
这次做起来有点像TDD,是先写test,再写实现的。不同的是,我一口气几乎把全部的tests都先写出来了。因为先用来测ddd888的解答。然后才写我自己的。对于调试还是挺有帮助的。一下子就把两个bugs找到。:D
基本思路在5楼。还是用了一个mod。其实是瞎折腾。真的要投,估计是要用ddd888的那个。:$
ddd888的我就是改了上面我说的跟x比较,还有就是把开始的值往x靠近一些。
请大家指教。
#include <iostream>
#include <assert.h>
#include <vector>
using namespace std;

vector<int>& multiple(int x, int y) {
        vector<int> ret;
        if (y>=x) {
                int inc[] = { 0, 4, 6, 8 };
                int period = 12;
                int num_inc = sizeof(inc)/sizeof(int);
                ret.reserve(((y-x)/period+1)*num_inc);
                int start = x - x % period + period;
                int pre = start - period;
                for (int i=0; i<num_inc; i++) {
                        int pre1 = pre+inc;
                        if (pre1>y) break;
                        if (pre1>=x) {
                                ret.push_back(pre1);
                        }
                }
                int cur = start;
                int stop = y - period;
                for (; cur <= stop ; cur+=period) {
                        for (int i=0; i<num_inc; i++) {
                                ret.push_back(cur+inc);
                        }
                }
                if (y>=start) {
                        int post = cur;
                        for (int i=0; i<num_inc; i++) {
                                int post1 = post+inc;
                                if (post1>y) break;
                                if (post1>=x) {
                                        ret.push_back(post1);
                                }
                        }
                }
        }       
        return ret;
}

vector<int> multiple_ddd888(int x, int y) {
        int start = x - 4 * 6;
        if (start<0) start = 0;
    int sequence1 = start+4;
    int sequence2 = start+6;
        vector<int> ret;
    while (true)
    {
      int iMin;
                if (sequence1 < sequence2)
                {
                        iMin = sequence1;
            sequence1 += 4;
                }
                else if (sequence1 == sequence2)
                {
                        iMin = sequence1;
            sequence1 += 4;
            sequence2 += 6;
                }
                else
                {
                        iMin = sequence2;
            sequence2 += 6;
                }

      if (iMin > y) {
            break;
      }

      if (iMin >= x) {
                        ret.push_back(iMin);
                }
    }
        return ret;
}


int main(int argc, char* argv[])
{
        int tests[] = {
                {{13, 12}, {0, -1, -1}},
                {{13, 13}, {0, -1, -1}},
                {{13, 14}, {0, -1, -1}},
                {{13, 15}, {0, -1, -1}},
                {{12, 12}, {1, 12, 12}},
                {{4, 4}, {1, 4, 4}},
                {{6, 6}, {1, 6, 6}},
                {{4, 12}, {4, 4, 12}},
                {{1, 12}, {4, 4, 12}},
                {{1, 11}, {3, 4, 8}},
                {{4, 11}, {3, 4, 8}},
                {{8, 31}, {8, 8, 30}},
                {{7, 30}, {8, 8, 30}},
                {{7, 31}, {8, 8, 30}},
        };
        for (unsigned int i=0; i<sizeof(tests)/sizeof(tests); i++) {
                int* input=tests;
                int* expected=tests;
                vector<int> actual;
                cout << "x:"<<input<<",y:"<<input<<": ";
                actual = multiple(input, input); // call the function
                //cout << actual.size() ;
                assert(expected==actual.size());
                if (actual.size()> 0) {
                        assert(expected==actual);
                        assert(expected==actual);
                }
                for (int j=0; j<actual.size(); j++) {
                        assert(actual % 4 == 0 || actual % 6 == 0);
                        cout << actual << '\t';
                }
                cout << endl;
        }

    return 0;
}

cais 发表于 21-4-2013 00:34:58

原帖由 ricowang 于 20-4-2013 21:35 发表 http://www.freeoz.org/ibbs/images/common/back.gif


效率根本不是问题,除非被明确提及
在澳洲人值钱还是机器值钱?
就像前面那个DD888那样,写个以为很节约的程序,实际上呢,还是个错误的
如果你是老板你选哪个?呵呵
ls说得太绝对了。我是不同意这种不注重效率的观点的。用机器来填补算法的低效,是种过时的观点。能在充分利用单位机器的资源,当然不能放过了。
特别是对于现在很多提供cloud based服务的公司,这种因为低效而来的成本会随着客户数目的增加被放大的。
还有一点,能够直接加机器就能线性增长性能的系统,并不容易做,增长总是有个极限的。而且我估计写出这种系统的人也不太肯轻易认识机器便宜就放弃优化的机会。;P
另外还有些情况下,是要充分挖掘单机性能的,比如手机, mobile,还比如这个职位,明确写了是做robotics, low lever driver等等。
有时候可能会因为可维护性而否定某些实现或算法(比如我上面的那个),但是不至于以机器便宜为理由。
讨论一下。:)

DDD888 发表于 21-4-2013 09:22:08

原帖由 cais 于 21-4-2013 00:34 发表 http://www.freeoz.org/ibbs/images/common/back.gif

ls说得太绝对了。我是不同意这种不注重效率的观点的。用机器来填补算法的低效,是种过时的观点。能在充分利用单位机器的资源,当然不能放过了。
特别是对于现在很多提供cloud based服务的公司,这种因为低效而来的 ...

I agree with you.:victory:

ricowang 发表于 21-4-2013 09:27:08

原帖由 cais 于 20-4-2013 22:34 发表 http://www.freeoz.org/ibbs/images/common/back.gif

ls说得太绝对了。我是不同意这种不注重效率的观点的。用机器来填补算法的低效,是种过时的观点。能在充分利用单位机器的资源,当然不能放过了。
特别是对于现在很多提供cloud based服务的公司,这种因为低效而来的 ...

真正对性能很在意的应用是极少的,说到mobile andriod的手机开发是用Java的吧?

如果你开发后台支撑系统,单纯考虑系统资源也未必合适,随着业务量的增加,硬件扩展是早晚的事情
硬件成本/软件成本(软件的复杂度)之间需要一个平衡

DDD888 发表于 21-4-2013 09:27:49

原帖由 ricowang 于 20-4-2013 21:56 发表 http://www.freeoz.org/ibbs/images/common/back.gif


不使用除法或者是modulo运算,你是写不出来的
你的程序本身就是错误的,连x都没有用到,不值一提

I don't want to submit source code 100% correct and efficient on the web now. The job application process is in progress.

FYI, I am not submitting my cv for this job.

All I do is for fun.

ricowang 发表于 21-4-2013 09:29:52

原帖由 cais 于 20-4-2013 22:19 发表 http://www.freeoz.org/ibbs/images/common/back.gif
这个题目虽然说要the set of xxx,但是我觉得并不需要返回一个std::set或者一个set class。只需要确保返回的数里面没有重复就行了。
ddd888的做法,只需要在考虑要不要算上iMin时加上一个判断 if (iMin>=x) 就好了。 ...

第一个函数是错的,函数里面的自动变量返回reference,这个reference是无效的

cais 发表于 21-4-2013 16:55:31

原帖由 ricowang 于 21-4-2013 09:29 发表 http://www.freeoz.org/ibbs/images/common/back.gif


第一个函数是错的,函数里面的自动变量返回reference,这个reference是无效的
嗯,我的c++不好,写的时候也是挺怀疑的。是按照java来写的。
可能是compiler帮我把它弄对了。

cais 发表于 14-5-2013 17:51:02

Check out this update from Daniel Barrett @linkedin

Any C++ Developers looking for a new role in Sydney and able to start next week?

:)

planetkeeper 发表于 14-5-2013 19:32:34

Daniel Barrett 是不太靠谱中介里排名前十的。。。
页: [1] 2
查看完整版本: 又看到一个c++的职位