本文介绍了最大的两个数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 大家好, 在采访中经常会问到以下问题 如何在不使用关系的情况下找到最大的2个数字 运营商? 我看到的解决方案是 (a + b + abs(ab))/ 2; 有没有比这更好的解决方案.... ?????Hi all,The following question is asked frequently in interviewsHow to find the greatest of 2 numbers without using relationaloperators ?the solution i have seen is( a+b + abs(a-b) ) /2 ;is there any better solution than this ....?????推荐答案 aa*****@gmail.com 说: 大家好, 以下问题在采访中经常被问到 如何在不使用关系的情况下找到最大的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()使用 是一个非常好的选择,并且使用关系运算符而不是你显示的代码的一个主要优点是你避免使用两个补充, 减法,可能是一个函数调用,一个除法。你也避免了不到三个溢出危险。 所以我对面试官的回答是:先生(或女士),我猜你好吗正在寻找一个技巧答案,但我没有。我所拥有的只是 正确答案,即 - 使用关系运算符。这是正确的 工程解决方案。我完全可以接受这样做可能会有一个好奇的和有趣的诀窍,但是 - 不管它是什么 - 它不会像 听起来像使用一个解决方案关系运算符。如果你想雇用一个可以玩程序化技巧的人,你就不会想要我;请在其他地方看看 ,因为我是程序员,而不是舞台魔术师,而且我是在寻找理解这一点的客户的。但是,如果你追随某人,那么可以指着皇帝说为什么那个傻男人不去?b / b 穿上衣服?'',某人可以写清楚,简洁,明显的代码,并使用 合适的工作人员为正确的工作,然后请问你的下一个 问题。 - Richard Heathfield< http://www.cpax.org.uk> 电子邮件:-http:// www。 + rjh @ 谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php> Usenet是一个奇怪的放置" - dmr 1999年7月29日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.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."--Richard Heathfield <http://www.cpax.org.uk>Email: -http://www. +rjh@Google users: <http://www.cpax.org.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.com说:>aa*****@gmail.com 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。 你被录用了。 祝你好运 - jayOr perhaps that was the "trick" answer the interviewer was lookingfor.You''re hired.Best regards--jay 所以我对面试官的回答是是:先生(或女士),我猜你们这需要一个技巧答案,但我没有一个。我所拥有的只是 正确答案,即 - 使用关系运算符。这是正确的 工程解决方案。我完全可以接受这样做可能会有一个好奇的和有趣的诀窍,但是 - 不管它是什么 - 它不会像 听起来像使用一个解决方案关系运算符。如果你想雇用一个可以玩程序化技巧的人,你就不会想要我;请在其他地方看看 ,因为我是程序员,而不是舞台魔术师,而且我是在寻找理解这一点的客户的。但是,如果你追随某人,那么可以指着皇帝说为什么那个傻男人不去?b / b 穿上衣服?'',某人可以写清楚,简洁,明显的代码,并使用 合适的工作人员为正确的工作,然后请问你的下一个 问题。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." 搞笑!funny! 这篇关于最大的两个数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-13 16:18