最大的两个数字

编程入门 行业动态 更新时间:2024-10-11 21:25:21
本文介绍了最大的两个数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好, 在采访中经常会问到以下问题 如何在不使用关系的情况下找到最大的2个数字 运营商? 我看到的解决方案是 (a + b + abs(ab))/ 2; 有没有比这更好的解决方案.... ?????

Hi all, The following question is asked frequently in interviews How to find the greatest of 2 numbers without using relational operators ? the solution i have seen is ( a+b + abs(a-b) ) /2 ; is there any better solution than this ....?????

推荐答案

aa*****@gmail 说: 大家好, 以下问题在采访中经常被问到 如何在不使用关系的情况下找到最大的2个数字 运营商? Hi all, The following question is asked frequently in interviews How to find the greatest of 2 numbers without using relational operators ?

正确的答案是:非常糟糕。关系运算符的原因是 。

The proper answer is: badly. The relational operators are there for a reason.

我看到的解决方案是 (a + b + abs(ab))/ 2; 有没有比这更好的解决方案.... ????? the solution i have seen is ( a+b + abs(a-b) ) /2 ; is there any better solution than this ....?????

是 - 使用关系运算符!无论如何,abs()使用 是一个非常好的选择,并且使用关系运算符而不是你显示的代码的一个主要优点是你避免使用两个补充, 减法,可能是一个函数调用,一个除法。你也避免了不到三个溢出危险。 所以我对面试官的回答是:先生(或女士),我猜你好吗<正在寻找一个技巧答案,但我没有。我所拥有的只是 正确答案,即 - 使用关系运算符。这是正确的 工程解决方案。我完全可以接受这样做可能会有一个好奇的和有趣的诀窍,但是 - 不管它是什么 - 它不会像 听起来像使用一个解决方案关系运算符。如果你想雇用一个可以玩程序化技巧的人,你就不会想要我;请在其他地方看看 ,因为我是程序员,而不是舞台魔术师,而且我是在寻找理解这一点的客户的。但是,如果你追随某人,那么可以指着皇帝说为什么那个傻男人不去?b / b 穿上衣服?'',某人可以写清楚,简洁,明显的代码,并使用 合适的工作人员为正确的工作,然后请问你的下一个 问题。 - Richard Heathfield< www.cpax.uk> 电子邮件:-http:// www。 + rjh @ 谷歌用户:< www.cpax.uk/prg/writings/googly.php> Usenet是一个奇怪的放置" - dmr 1999年7月29日

Yes - use the relational operators! It''s a pretty good bet that abs() uses one anyway, and one major advantage of using a relational operator rather than the code you show is that you avoid the two additions, the subtraction, possibly a function call, and a division. You also avoid no fewer than three overflow hazards. So my answer to the interviewer would be: "sir (or madam), I guess that you are looking for a trick answer, but I don''t have one. All I have is the correct answer, which is - use a relational operator. That is the proper engineering solution. I can fully accept that there might be a curious and interesting trick for doing this, but - whatever it is - it will not be as sound a solution as using a relational operator. If you want to hire someone who can play programmatic tricks, you don''t want me; please look elsewhere, because I am a programmer, not a stage magician, and I am looking for a client who understands this. But if you are after someone who can point at the Emperor and say ''why doesn''t that silly man go and get dressed?'', someone who can write clear, concise, obvious code, and use the right operators for the right jobs, then please ask your next question." -- Richard Heathfield <www.cpax.uk> Email: -www. +rjh@ Google users: <www.cpax.uk/prg/writings/googly.php> "Usenet is a strange place" - dmr 29 July 1999

星期五,2007年12月7日07:46:04 +0000,Richard Heathfield < rj * @ see .sig.invalidwrote: On Fri, 07 Dec 2007 07:46:04 +0000, Richard Heathfield <rj*@see.sig.invalidwrote: > aa ***** @ gmail说: >aa*****@gmail said: >大家好, 在采访中经常会问到以下问题 如何在不使用关系运算符的情况下找到最多的2个数字? >Hi all,The following question is asked frequently in interviewsHow to find the greatest of 2 numbers without using relationaloperators ?

正确的答案是:非常糟糕。关系运算符是有原因的。

The proper answer is: badly. The relational operators are there for areason.

>我看到的解决方案是 (a + b + abs(ab))/ 2; 有没有比这更好的解决方案.... ????? >the solution i have seen is ( a+b + abs(a-b) ) /2 ;is there any better solution than this ....?????

是的 - 使用关系运算符!无论如何,abs()使用是一个非常好的选择,使用关系运算符而不是你显示的代码的一个主要优点是你避免了两个添加,减法,可能是函数调用和除法。你也避免了不到三次溢出危险。

Yes - use the relational operators! It''s a pretty good bet that abs() usesone anyway, and one major advantage of using a relational operator ratherthan the code you show is that you avoid the two additions, thesubtraction, possibly a function call, and a division. You also avoid nofewer than three overflow hazards.

同意。

Agree.

>所以我对面试官的回答是:先生(或者)女士),我想你正在寻找一个技巧答案,但我没有。我所拥有的只是正确答案,即使用关系运算符。这是正确的工程解决方案。我完全可以接受这样做可能有一个好奇和有趣的技巧,但是 - 不管它是什么 - 它不会像使用关系运算符那样成为解决方案。如果你想雇用一个可以玩程序化技巧的人,你就不要我了;请在其他地方看看,因为我是程序员,而不是舞台魔术师,而且我正在寻找了解这一点的客户。但是,如果你追随的是一个可以指向皇帝并且说为什么那个傻男人不去穿衣服?的人,那些可以写出清晰,简洁,明显的代码的人,并使用正确的操作员为正确的工作,然后请问你的下一个问题。 >So my answer to the interviewer would be: "sir (or madam), I guess that youare looking for a trick answer, but I don''t have one. All I have is thecorrect answer, which is - use a relational operator. That is the properengineering solution. I can fully accept that there might be a curious andinteresting trick for doing this, but - whatever it is - it will not be assound a solution as using a relational operator. If you want to hiresomeone who can play programmatic tricks, you don''t want me; please lookelsewhere, because I am a programmer, not a stage magician, and I amlooking for a client who understands this. But if you are after someonewho can point at the Emperor and say ''why doesn''t that silly man go andget dressed?'', someone who can write clear, concise, obvious code, and usethe right operators for the right jobs, then please ask your nextquestion."

或许这就是诡计回答面试官正在寻找 for。 你被录用了。 祝你好运 - jay

Or perhaps that was the "trick" answer the interviewer was looking for. You''re hired. Best regards -- jay

所以我对面试官的回答是是:先生(或女士),我猜你们这需要一个技巧答案,但我没有一个。我所拥有的只是 正确答案,即 - 使用关系运算符。这是正确的 工程解决方案。我完全可以接受这样做可能会有一个好奇的和有趣的诀窍,但是 - 不管它是什么 - 它不会像 听起来像使用一个解决方案关系运算符。如果你想雇用一个可以玩程序化技巧的人,你就不会想要我;请在其他地方看看 ,因为我是程序员,而不是舞台魔术师,而且我是在寻找理解这一点的客户的。但是,如果你追随某人,那么可以指着皇帝说为什么那个傻男人不去?b / b 穿上衣服?'',某人可以写清楚,简洁,明显的代码,并使用 合适的工作人员为正确的工作,然后请问你的下一个 问题。 So my answer to the interviewer would be: "sir (or madam), I guess that you are looking for a trick answer, but I don''t have one. All I have is the correct answer, which is - use a relational operator. That is the proper engineering solution. I can fully accept that there might be a curious and interesting trick for doing this, but - whatever it is - it will not be as sound a solution as using a relational operator. If you want to hire someone who can play programmatic tricks, you don''t want me; please look elsewhere, because I am a programmer, not a stage magician, and I am looking for a client who understands this. But if you are after someone who can point at the Emperor and say ''why doesn''t that silly man go and get dressed?'', someone who can write clear, concise, obvious code, and use the right operators for the right jobs, then please ask your next question."

搞笑!

funny!

更多推荐

最大的两个数字

本文发布于:2023-11-30 07:56:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1649262.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:两个   数字

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!