面试问题(简单还是努力?) [英] interview question (easy or hard?)

查看:65
本文介绍了面试问题(简单还是努力?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我被要求为C / C ++程序员提出面试问题

(CAD / CAE软件)

我出现了以下

--------------------------------------- -------------------------------------------------

浮动乐趣(浮动值)

{

浮动f1 = 0。,f2 =值;

浮动收费= value / 1000。;

浮动结果,tmp;

while(1){

result =(f2 + f1)/ 2。 ;

tmp =结果*结果值;


if(fabs(tmp)< = tol)

break;


if(tmp> 0。){

f2 =结果;

}否则{

f1 =结果;

}

}

返回结果;

}


1.上述近似算法的结果是什么?

a)模数值为1000.

b)平方根值。

c)pi


2.以下哪个值接近返回值

fun(9。)?

a)3。

b)3.0015

c)3.1415

3. while循环下面的哪些值没有结束?

a)0。

b)0.5

c)1。


4.纠正上一个错误。

--------------------------------------------- -------------------------------------------

您认为练习的难度级别是什么?

还有其他评论吗?


问候

Kostas

解决方案

在2007-11-22 21:50,kostas写道:




我被要求为C / C ++程序员提出面试问题

(CAD / CAE软件)

我想出了以下内容

---------------------------------------------- ------------------------------------------

浮动乐趣(浮动值)

{

浮动f1 = 0。,f2 =值;

浮动tol =值/ 1000 .;

浮动结果,tmp;

而(1){

result =(f2 + f1)/ 2 .;

tmp =结果*结果值;


if(fabs(tmp)< = tol)

break;


if(tmp> 0。){

f2 =结果;

}否则{

f1 =结果;

}

}

返回结果;

}


1.什么是上述近似算法的结果?

a)值模数1000.

b)平方根值。

c)pi


2.下面哪个值接近返回值

fun(9。)?

a)3。

b)3.0015

c)3.1415

3. while循环下面的哪些值没有结束?

a )0。

b)0.5

c)1。


4.纠正上一个错误。

-------------- -------------------------------------------------- ------------------------

您认为练习的难度级别是多少?
还有其他意见吗?



我想这取决于你想要测试的内容。以上将测试申请人如何处于浮点数学和执行计算中的好处,如果这是你想要的话,那么这是一个好的问题。


-

Erik Wikstr ?? m


kostas写道:




我被要求为C / C ++程序员提出面试问题

(CAD / CAE软件)

我想出了以下

-------------------------------- -------------------------------------------------- ------

浮动乐趣(浮动值)

{

浮动f1 = 0。,f2 =值;

float tol = value / 1000 .;

浮动结果,tmp;

而(1){

result =( f2 + f1)/ 2 .;

tmp =结果*结果值;


if(fabs(tmp)< = tol)

休息;


if(tmp> 0。){

f2 =结果;

}否则{

f1 =结果;

}

}

返回结果;

}


1.结果是什么以上近似算法?

a)值模数1000.

b)平方根值。

c)pi


2.以下哪个值接近返回值

fun(9。)?

a)3。

b)3.0015

c)3.1415

3. while循环下面的哪些值没有结束?

a)0 。

b)0.5

c)1。


4.纠正上一个错误。


----------------------------------------------- -----------------------------------------

什么你认为是练习的难度级别



它是'不难。


请注意,这不是语言问题。


还有其他评论吗?



1)我会把那个循环写得有些不同:


浮动乐趣(浮动值)

{

浮动较低= 0;

浮动上限=值;

浮动relative_error = value / 1000 .;

while(true){

浮动平均值=(低+上)/ 2 .;

浮动tmp =平均值*平均值 - 值;


if(std :: abs(tmp)< = relative_error){

return(mean);

}
<如果(tmp> 0。){

upper = mean;

}其他$


}

}

}

2)你也可以问一下这个函数的剩余bug是不是

终止负值。它应该声明一些东西,抛出和

异常或返回一些有用的东西;但它不应该进入一个

无限循环。

最好


Kai-Uwe Bux


2007年11月22日星期四12:50:38 -0800,kostas写道:




我被要求为C / C ++程序员提出面试问题

(CAD / CAE软件)

我想出了以下内容



[snip]





其他人的积分很好。这不是一个真正的语言

问题。更多你能读取未注释的代码吗?题。这将是什么让我害怕的地狱:-)


我没有仔细阅读代码(只有循环的前两行),

但它似乎是一个找到平方根问题。我建议

这个问题看起来像这样:


这是一个查找平方根的算法。它使用二分(?)。


在哪些情况下循环不会终止? (没有多项选择)

你怎么能让这个算法重复使用,而不只是找到

平方根?


我'我已经使用了这个问题的一个变体,对代码的要求我可以执行
,它已经为人们除草做了奇迹。第二个

问题及其对运行代码的要求通常是这样的,因为

代码真的很糟糕,或者他们放弃了。


这是一个很好的问题,但它可以向你展示更多关于

候选人的信息,而不是你将用你原来的一套问题来学习。


-

Sohail Somani
http:// uint32t。 blogspot.com


Hi
I was asked to propose an interview question for C/C++ programmers
(CAD/CAE software)
I came up with the following
----------------------------------------------------------------------------------------
float fun(float value)
{
float f1 =0., f2 = value;
float tol = value/1000.;
float result,tmp;
while(1) {
result = (f2+f1)/2.;
tmp = result*result-value;

if(fabs(tmp)<=tol)
break;

if(tmp>0.) {
f2 = result;
}else {
f1 = result;
}
}
return result;
}

1. What is the result of the above approximate algorithm ?
a) value modulo 1000.
b) square root of value.
c) pi

2. Which of the values below is closer to the return value of
fun(9.) ?
a) 3.
b) 3.0015
c) 3.1415

3. For which of the values below the while loop does not end ?
a) 0.
b) 0.5
c) 1.

4. Correct the previous bug.
----------------------------------------------------------------------------------------
What do you think is the difficulty level of the exercise
Any other comments?

regards
Kostas

解决方案

On 2007-11-22 21:50, kostas wrote:

Hi
I was asked to propose an interview question for C/C++ programmers
(CAD/CAE software)
I came up with the following
----------------------------------------------------------------------------------------
float fun(float value)
{
float f1 =0., f2 = value;
float tol = value/1000.;
float result,tmp;
while(1) {
result = (f2+f1)/2.;
tmp = result*result-value;

if(fabs(tmp)<=tol)
break;

if(tmp>0.) {
f2 = result;
}else {
f1 = result;
}
}
return result;
}

1. What is the result of the above approximate algorithm ?
a) value modulo 1000.
b) square root of value.
c) pi

2. Which of the values below is closer to the return value of
fun(9.) ?
a) 3.
b) 3.0015
c) 3.1415

3. For which of the values below the while loop does not end ?
a) 0.
b) 0.5
c) 1.

4. Correct the previous bug.
----------------------------------------------------------------------------------------
What do you think is the difficulty level of the exercise
Any other comments?

I guess it depends on what you want to test. The above will test how
good the applicant is at floating point math and performing calculations
in his head, if that is what you want then it is an OK question.

--
Erik Wikstr??m


kostas wrote:

Hi
I was asked to propose an interview question for C/C++ programmers
(CAD/CAE software)
I came up with the following
----------------------------------------------------------------------------------------
float fun(float value)
{
float f1 =0., f2 = value;
float tol = value/1000.;
float result,tmp;
while(1) {
result = (f2+f1)/2.;
tmp = result*result-value;

if(fabs(tmp)<=tol)
break;

if(tmp>0.) {
f2 = result;
}else {
f1 = result;
}
}
return result;
}

1. What is the result of the above approximate algorithm ?
a) value modulo 1000.
b) square root of value.
c) pi

2. Which of the values below is closer to the return value of
fun(9.) ?
a) 3.
b) 3.0015
c) 3.1415

3. For which of the values below the while loop does not end ?
a) 0.
b) 0.5
c) 1.

4. Correct the previous bug.

----------------------------------------------------------------------------------------
What do you think is the difficulty level of the exercise

It''s not hard.

Note that it is not a language question.

Any other comments?

1) I would write that loop a little different:

float fun(float value)
{
float lower = 0;
float upper = value;
float relative_error = value/1000.;
while ( true ) {
float mean = (lower + upper )/2.;
float tmp = mean * mean - value;

if( std::abs(tmp) <= relative_error ) {
return ( mean );
}

if(tmp>0.) {
upper = mean;
}else {
lower = mean;
}
}
}
2) You could also ask about the remaining bug of the function not
terminating for negative values. It should assert something, throw and
exception or return something usefull; but it should not go into an
infinite loop.
Best

Kai-Uwe Bux


On Thu, 22 Nov 2007 12:50:38 -0800, kostas wrote:

Hi
I was asked to propose an interview question for C/C++ programmers
(CAD/CAE software)
I came up with the following

[snip]

Hi,

The points the others are making are good. It isn''t really a language
question. More a "can you read uncommented code" question. Which would
scare me the hell away :-)

I didn''t read the code too closely (only first two lines of the loop),
but it seems to be a find-the-square-root question. I would recommend
that the question look something like this:

This is an algorithm to find the square root. It uses bisection(?).

For which cases does the loop not terminate? (no multiple choice)
How would you make this algorithm reusable to more than just finding
square roots?

I''ve used a variant of this question with a requirement on code I can
execute and it has done wonders for weeding people out. The second
question with its requirements on running code usually does it because
either the code is really really bad, or they give up.

Good question to ask, but it can show you so much more about the
candidate than what you will learn with your original set of questions.

--
Sohail Somani
http://uint32t.blogspot.com


这篇关于面试问题(简单还是努力?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆