由买买提看人间百态

topics

全部话题 - 话题: 2147483647
1 2 下页 末页 (共2页)
a***e
发帖数: 27968
1
来自主题: Hardware版 - 故障求助:Windows 7与USB 3.0驱动
http://msft.digitalrivercontent.net/win/X17-24208.iso 2147483647 X17-24208.iso Windows 7 Home Premium x86 English
http://msft.digitalrivercontent.net/win/X17-24209.iso 2147483647 X17-24209.iso Windows 7 Home Premium x64 English
http://msft.digitalrivercontent.net/win/X17-24268.iso 2147483647 X17-24268.iso Windows 7 Professional x86 Chinese
http://msft.digitalrivercontent.net/win/X17-24269.iso 2147483647 X17-24269.iso Windows 7 Professional x64 Chinese
http://msft.digitalrivercontent.net/win/X17-... 阅读全帖
T*********e
发帖数: 39815
2
来自主题: sysop版 - 这几个都是用机器人的?
========== 发文次数排行榜 ==========
名次 代号 昵称 次数
==== ======================================================
[ 1] att new at&t 2147483647
[ 2] gzheng huazi 2147483647
[ 3] beet008 beet008 2147483647
[ 4] donroberto donroberto 2147483647
[ 5] iMacadamia aka macadamia 2147483647
i**********e
发帖数: 1145
3
基本思路对,但可能有些 case 考虑不全,例如 INT_MIN = -2147483648,不是 -
2147483647(考虑 int 为 32-bit),要小心处理这个溢出,很多人很容易掉进的陷阱。
还有就是 "1a",应该 output 是 1,而不是 0。
不过我觉得这些细节不大要紧,最重要是问好问题来,知道 input requirement就好了。
可以在这里执行你的代码:
http://www.leetcode.com/onlinejudge
Problem: String to Integer (atoi)
Progress: 23/30 test cases passed.
input output expected
"-2147483648" 2147483647 -2147483648
"-2147483649" 2147483647 -2147483648
z*********v
发帖数: 22
4
http://www.bmwofthewoodlands.com/VehicleSearchResults?series=X5 35d&maxMPG=2147483647&maxPrice=2147483647&minYear=2011&maxYear=2013&bodyType=SUV&minMPG=-2147483648&search=new&zipCode=&trim=AWD 4dr SUV&make=BMW&minPrice=35000&pageNumber=1&visitedVD=true
this dealer has quite a few x5 diesel
w**z
发帖数: 8232
5
来自主题: JobHunting版 - atoi很不好写,头都大了...
我再贴一下Java的sourcecode。不懂为什么要把正数转成负数再查溢出呢?有什么好处?
code里有Author的comments
// Accumulating negatively avoids surprises near MAX_VALUE
/**
* Parses the string argument as a signed integer in the radix
* specified by the second argument. The characters in the string
* must all be digits of the specified radix (as determined by
* whether {@link java.lang.Character#digit(char, int)} returns a
* nonnegative value), except that the first character may be an
* ASCII minus sig... 阅读全帖
w**z
发帖数: 8232
6
Source Code from Java
/*
* @author Lee Boynton
* @author Arthur van Hoff
* @author Josh Bloch
* @version 1.92, 04/07/06
* @since JDK1.0
*/
/**
* Parses the string argument as a signed integer in the radix
* specified by the second argument. The characters in the string
* must all be digits of the specified radix (as determined by
* whether {@link java.lang.Character#digit(char, int)} returns a
* nonnegative value), except that the first character may be an
* A... 阅读全帖
x****f
发帖数: 78
7
来自主题: JobHunting版 - 我编程会不如烙印???放屁
木有问题呀!
int x = 2147483647;
int y = 2147483646;
x = x + y;
y = x - y;
x = x - y;
Console.WriteLine("X: "+x+", Y: "+y);
X: 2147483646, Y: 2147483647
w********e
发帖数: 8594
k**o
发帖数: 15334
9
扯淡,美国犯罪率从92年开始都是逐年下降。80-90年那时候才乱呢。
以洛杉矶暴动为高潮,之后美国社会有很大的改变,犯罪率降了非常多。
https://www.usnews.com/dims4/USNEWS/f5fa0aa/2147483647/resize/970x/quality/
85/?url=%2Fcmsmedia%2F78%2F90%2F75bb622a48c289f2b8b64eb945e9%2F160926-
violentcrimerate-editorial.jpg
g******t
发帖数: 18158
10
http://www.politico.com/story/2017/10/23/trump-401-k-contributions-tweet-244059
https://static.politico.com/dims4/default/8b32c78/2147483647/resize/971x/
quality/90/?url=http%3A%2F%2Fstatic.politico.com%2Fbb%2Ffa%
2F8a7dd7264a5d94095631fd19e1d5%2F12-donald-trump-13-ap-1160.jpg
“There will be NO change to your 401(k). This has always been a great and
popular middle class tax break that works, and it stays!” President Donald
Trump tweeted Monday. | Matt Rourke/AP
Trump: 'There will be no change to... 阅读全帖
c*****t
发帖数: 10738
11
来自主题: Military版 - 川普这是要吃包子豆腐?
https://static.politico.com/dims4/default/201e06d/2147483647/resize/1160x%3E
/quality/90/?url=https%3A%2F%2Fstatic.politico.com%2Fb0%2F7d%
2Fbe217b95456fb4d32ada8ace70cd%2F190628-trump-xi-ap-773.jpg
d**********r
发帖数: 24123
s*****n
发帖数: 1998
13
来自主题: Military版 - 我这个外行说句沉船的话吧
二十多米长
不算太小了


: 感觉并不是太大的船啊。塞这么多人进去?

: http://ca-times.brightspotcdn.com/dims4/default/e6603a4/2147483647/strip/true/crop/3024x2016 0 94/resize/1680x1120!/quality/90/?url=https://ca-times.brightspotcdn.com/ad/52/3cc6c70f4e76996a2f2245add1cb/la-me-boat-fire-103-h.jpg

m********g
发帖数: 10469
l*******g
发帖数: 27064
15
来自主题: Automobile版 - laoselang国内翻墙又一证据
尼玛
丰田拥趸最搞笑的是他说丰田好啊就是好,什么证据都不要
他说美国车德国车就是烂,也是什么证据都没有,张嘴就来
别人要是说个丰田有啥问题,必须要严密的官方的数据证据,哪怕是用官方证据稍微加
减乘除一下也不行,否则就是编造抹黑。新闻报道也不行,因为没有完整数据
尤其重要的是,被丰田收买的婊子媒体cr,jd编造的数据他们就当圣经
天天拿来忽悠人
至于丰田warranty使用多的证据,我出示过无数次了
两个不同来源:
1、发信人: ESPNDOTCOM (Tim), 信区: Automobile
标 题: FORD 现在质量很好, 劝买日车的三思.
发信站: BBS 未名空间站 (Fri Aug 29 13:48:10 2014, 美东)
之所以这样说是因为我朋友是替美国一家很大的二手车代理商做warranty精算. FORD最
近5年的理陪率,包括欧洲,亚洲,美国. 一直都是前三低, 亚洲车来说, 韩国最近4,5年
的车已经比丰田好了. 就是数据说话,决无造谣.
2、
丰田自动加速问题多,也贴过n次了
丰田投诉多
还有,来来,看看我被丰田托抹黑的“编造数据”(nhtsa 2013年前收... 阅读全帖
i****x
发帖数: 17565
16
来自主题: Automobile版 - =====都进来跪拜老色狼=====
先随便读几篇老色狼(日黑)的帖子,看看能不能看出牛逼之处在哪?
发信人: laoselang (LAOSELANG(好吧,别打了,我就是兔子)), 信区: Automobile
标 题: Re: 试开了两天sienna 2013,有点晕车
发信站: BBS 未名空间站 (Thu Jan 22 00:23:21 2015, 美东)
lol
跑车?
你最快开到多少?
软烂悬挂也能说成是硬,
烂的一b,开起来七歪八扭的丰田烂货也能当“跑车”开
丰田车主果然都是懂车的
发信人: laoselang (LAOSELANG(好吧,别打了,我就是兔子)), 信区: Automobile
标 题: Re: 2015 fusion s otd
发信站: BBS 未名空间站 (Mon Mar 23 20:04:42 2015, 美东)
尼玛,真不要脸
我说的哪个不是事实?
1、丰田自动加速没解决,去年底的新闻还在重启调查
2、丰田软件bug成堆,隐患多多
3、丰田车筷子悬挂软烂,漂移打滑是常事,操控就是渣
4、丰田软屁股,一撞就露馅
5、丰田还有刹车失灵,minivan自动开门,车祸气囊不开等安全隐患... 阅读全帖
i****x
发帖数: 17565
17
来自主题: Automobile版 - @laoselang 帮帮忙 关于Ford Edge
老色狼这贴里确实很正常
不过凑上来的应该不是因为这贴。你可以看看下面这些是佛还是屎
发信人: laoselang (LAOSELANG(好吧,别打了,我就是兔子)), 信区: Automobile
标 题: Re: 试开了两天sienna 2013,有点晕车
发信站: BBS 未名空间站 (Thu Jan 22 00:23:21 2015, 美东)
lol
跑车?
你最快开到多少?
软烂悬挂也能说成是硬,
烂的一b,开起来七歪八扭的丰田烂货也能当“跑车”开
丰田车主果然都是懂车的
发信人: laoselang (LAOSELANG(好吧,别打了,我就是兔子)), 信区: Automobile
标 题: Re: 2015 fusion s otd
发信站: BBS 未名空间站 (Mon Mar 23 20:04:42 2015, 美东)
尼玛,真不要脸
我说的哪个不是事实?
1、丰田自动加速没解决,去年底的新闻还在重启调查
2、丰田软件bug成堆,隐患多多
3、丰田车筷子悬挂软烂,漂移打滑是常事,操控就是渣
4、丰田软屁股,一撞就露馅
5、丰田还有刹车失灵,minivan自动开门,车... 阅读全帖
i****x
发帖数: 17565
18
发信人: laoselang (LAOSELANG(好吧,别打了,我就是兔子)), 信区: Automobile
标 题: Re: 试开了两天sienna 2013,有点晕车
发信站: BBS 未名空间站 (Thu Jan 22 00:23:21 2015, 美东)
lol
跑车?
你最快开到多少?
软烂悬挂也能说成是硬,
烂的一b,开起来七歪八扭的丰田烂货也能当“跑车”开
丰田车主果然都是懂车的
发信人: laoselang (LAOSELANG(好吧,别打了,我就是兔子)), 信区: Automobile
标 题: Re: 2015 fusion s otd
发信站: BBS 未名空间站 (Mon Mar 23 20:04:42 2015, 美东)
尼玛,真不要脸
我说的哪个不是事实?
1、丰田自动加速没解决,去年底的新闻还在重启调查
2、丰田软件bug成堆,隐患多多
3、丰田车筷子悬挂软烂,漂移打滑是常事,操控就是渣
4、丰田软屁股,一撞就露馅
5、丰田还有刹车失灵,minivan自动开门,车祸气囊不开等安全隐患
6、丰田车技术老旧,价格高昂,性价比同级别最低
7、丰田war... 阅读全帖
i****x
发帖数: 17565
19
来自主题: Automobile版 - 新普锐斯获得Euro-NCAP五星满分
发信人: laoselang (LAOSELANG(好吧,别打了,我就是兔子)), 信区: Automobile
标 题: Re: 试开了两天sienna 2013,有点晕车
发信站: BBS 未名空间站 (Thu Jan 22 00:23:21 2015, 美东)
lol
跑车?
你最快开到多少?
软烂悬挂也能说成是硬,
烂的一b,开起来七歪八扭的丰田烂货也能当“跑车”开
丰田车主果然都是懂车的
发信人: laoselang (LAOSELANG(好吧,别打了,我就是兔子)), 信区: Automobile
标 题: Re: 2015 fusion s otd
发信站: BBS 未名空间站 (Mon Mar 23 20:04:42 2015, 美东)
尼玛,真不要脸
我说的哪个不是事实?
1、丰田自动加速没解决,去年底的新闻还在重启调查
2、丰田软件bug成堆,隐患多多
3、丰田车筷子悬挂软烂,漂移打滑是常事,操控就是渣
4、丰田软屁股,一撞就露馅
5、丰田还有刹车失灵,minivan自动开门,车祸气囊不开等安全隐患
6、丰田车技术老旧,价格高昂,性价比同级别最低
7、丰田war... 阅读全帖
i****x
发帖数: 17565
20
没错,老色狼发帖都凭良心,一分钱不收十年如一次24x7揭批丰田。
发信人: laoselang (LAOSELANG(好吧,别打了,我就是兔子)), 信区: Automobile
标 题: Re: 试开了两天sienna 2013,有点晕车
发信站: BBS 未名空间站 (Thu Jan 22 00:23:21 2015, 美东)
lol
跑车?
你最快开到多少?
软烂悬挂也能说成是硬,
烂的一b,开起来七歪八扭的丰田烂货也能当“跑车”开
丰田车主果然都是懂车的
发信人: laoselang (LAOSELANG(好吧,别打了,我就是兔子)), 信区: Automobile
标 题: Re: 2015 fusion s otd
发信站: BBS 未名空间站 (Mon Mar 23 20:04:42 2015, 美东)
尼玛,真不要脸
我说的哪个不是事实?
1、丰田自动加速没解决,去年底的新闻还在重启调查
2、丰田软件bug成堆,隐患多多
3、丰田车筷子悬挂软烂,漂移打滑是常事,操控就是渣
4、丰田软屁股,一撞就露馅
5、丰田还有刹车失灵,minivan自动开门,车祸气囊不开等安全隐... 阅读全帖
i****x
发帖数: 17565
21
来自主题: Automobile版 - 职业车托月入数万元
你看看这些帖子值多少钱?
发信人: laoselang (LAOSELANG(好吧,别打了,我就是兔子)), 信区: Automobile
标 题: Re: 试开了两天sienna 2013,有点晕车
发信站: BBS 未名空间站 (Thu Jan 22 00:23:21 2015, 美东)
lol
跑车?
你最快开到多少?
软烂悬挂也能说成是硬,
烂的一b,开起来七歪八扭的丰田烂货也能当“跑车”开
丰田车主果然都是懂车的
发信人: laoselang (LAOSELANG(好吧,别打了,我就是兔子)), 信区: Automobile
标 题: Re: 2015 fusion s otd
发信站: BBS 未名空间站 (Mon Mar 23 20:04:42 2015, 美东)
尼玛,真不要脸
我说的哪个不是事实?
1、丰田自动加速没解决,去年底的新闻还在重启调查
2、丰田软件bug成堆,隐患多多
3、丰田车筷子悬挂软烂,漂移打滑是常事,操控就是渣
4、丰田软屁股,一撞就露馅
5、丰田还有刹车失灵,minivan自动开门,车祸气囊不开等安全隐患
6、丰田车技术老旧,价格高昂,性价比... 阅读全帖
i****x
发帖数: 17565
22
全球唯一良心的车媒是自媒体金字品牌老色狼。老色狼以一己之力迎战被丰田收买的cr
、jdpower、cd、mt等一干婊子车媒,以及被丰田收买的美国婊子政府和婊子道路安全
局,还有欧洲的婊子安全局,还有全球被丰田收买的几千万婊子用户,力挽狂澜,不分
胜负。
发信人: laoselang (LAOSELANG(好吧,别打了,我就是兔子)), 信区: Automobile
标 题: Re: 试开了两天sienna 2013,有点晕车
发信站: BBS 未名空间站 (Thu Jan 22 00:23:21 2015, 美东)
lol
跑车?
你最快开到多少?
软烂悬挂也能说成是硬,
烂的一b,开起来七歪八扭的丰田烂货也能当“跑车”开
丰田车主果然都是懂车的
发信人: laoselang (LAOSELANG(好吧,别打了,我就是兔子)), 信区: Automobile
标 题: Re: 2015 fusion s otd
发信站: BBS 未名空间站 (Mon Mar 23 20:04:42 2015, 美东)
尼玛,真不要脸
我说的哪个不是事实?
1、丰田自动加速没解决,去年底的新闻还在重... 阅读全帖
i****x
发帖数: 17565
23
来自主题: Automobile版 - Tomstat网友,你斗不过rihei的
你被人骗了火冒三丈来斗rihei,其实战斗力最多也就是个一腔热血的六四学生水平。
人家rihei,又名taigong,dehei,laoselang,说是训练有素的正规军都算贬低他了,
要说比喻应该是受过全面特殊技能训练的克格勃还外加一身核动力装甲才比较合适。人
家每天十几个小时在车版发帖工作,几个马甲能同时独占车版发帖量前三,不愠不火,
见风使舵,敌进我退,敌疲我打,全版所有人合起来都不一定能媲美人家战斗力。建议
你还是早早放弃幻想乖乖让rihei继续欺骗其他网友吧。
你估计不信,那我随手贴几个他的帖子你读读看服不服。
发信人: laoselang (LAOSELANG(好吧,别打了,我就是兔子)), 信区: Automobile
标 题: Re: 试开了两天sienna 2013,有点晕车
发信站: BBS 未名空间站 (Thu Jan 22 00:23:21 2015, 美东)
lol
跑车?
你最快开到多少?
软烂悬挂也能说成是硬,
烂的一b,开起来七歪八扭的丰田烂货也能当“跑车”开
丰田车主果然都是懂车的
发信人: laoselang (LAOSELANG(好吧,别打了,我... 阅读全帖
e**n
发帖数: 5876
24
来自主题: Automobile版 - 有买Ford Escape的吗?

rihei的马甲又老色狼, taigong, dehei等, 大家(特别是新人)要小心这个骗子. 他
谎话连篇, 你追问他, 他自然找不到, 然后让你自己找. 呵呵
前些日子Tomstat网友被这个ford托骗了, 上来骂, 但是rihei几个马甲轮番上阵,再加
上有十几个ford水军id. 根本骂不过的.
给你转个帖子你来看看rihei的战斗力
发信人: icefox (icefox), 信区: Automobile
标 题: Tomstat网友,你斗不过rihei的
发信站: BBS 未名空间站 (Thu Aug 11 00:26:49 2016, 美东)
你被人骗了火冒三丈来斗rihei,其实战斗力最多也就是个一腔热血的六四学生水平。
人家rihei,又名taigong,dehei,laoselang,说是训练有素的正规军都算贬低他了,
要说比喻应该是受过全面特殊技能训练的克格勃又穿上一身核动力装甲才比较合适。人
家每天十几个小时在车版发帖工作,几个马甲能同时独占车版发帖量前三,不愠不火,
见风使舵,敌进我退,敌疲我打,全版所有人合起来都不一定能媲美人家战斗力。建议
你还... 阅读全帖
i****x
发帖数: 17565
25
来自主题: Automobile版 - LEXUS 2016 ES 350
lz注意:这个id发帖权当放屁即可。这是他的工作
发信人: laoselang (LAOSELANG(好吧,别打了,我就是兔子)), 信区: Automobile
标 题: Re: 试开了两天sienna 2013,有点晕车
发信站: BBS 未名空间站 (Thu Jan 22 00:23:21 2015, 美东)
lol
跑车?
你最快开到多少?
软烂悬挂也能说成是硬,
烂的一b,开起来七歪八扭的丰田烂货也能当“跑车”开
丰田车主果然都是懂车的
发信人: laoselang (LAOSELANG(好吧,别打了,我就是兔子)), 信区: Automobile
标 题: Re: 2015 fusion s otd
发信站: BBS 未名空间站 (Mon Mar 23 20:04:42 2015, 美东)
尼玛,真不要脸
我说的哪个不是事实?
1、丰田自动加速没解决,去年底的新闻还在重启调查
2、丰田软件bug成堆,隐患多多
3、丰田车筷子悬挂软烂,漂移打滑是常事,操控就是渣
4、丰田软屁股,一撞就露馅
5、丰田还有刹车失灵,minivan自动开门,车祸气囊不开等安全隐患
6、丰田车技... 阅读全帖
W****t
发帖数: 8270
26
来自主题: ebiz版 - 这是怎么做到的
veron (贝隆) 共上站 61717 次,发表过 2147483647 篇文章
上次在 [Sun Apr 4 11:19:47 2010] 从 [173.225.] 到本站一游。
离线时间[因在线上或非常断线不详] 信箱:[ ] 身份: [用户]
伪币: [0.00](可用:0.00)
经验值:[0](无人问津) 表现值:[348164](神~~) 生命力:[6666]。
目前在站上,状态如下:
主菜单[2]
a******n
发帖数: 11246
27
来自主题: GiftCard版 - 请问如何买saks fifth avenue的gc?
请教一下,你是如果发了那么多负文的呢。。。
donroberto (donroberto) 共上站 4 次,发表过 -2147483647 篇文章
上次在 [Fri Jun 5 11:32:54 2009] 从 [129.137.] 到本站一游。
离线时间[因在线上或非常断线不详] 信箱:[ ] 身份: [用户]
伪币: [0.30](可用:0.10)
经验值:[0](新手上路) 表现值:[0](赶快加油) 生命力:[730]。
目前在站上,状态如下:
WEB浏览[3]
o**********t
发帖数: 406
28
来自主题: JobHunting版 - Goog面试挂了,回报一下本版
always try 2147483647
a***c
发帖数: 2443
29
来自主题: JobHunting版 - Goog面试挂了,回报一下本版
2147483647 = 2^31 - 1 ; test for integer overflow.
i**********e
发帖数: 1145
30
来自主题: JobHunting版 - 这题谁知道答案?
这题蛮有意思的,我刚写完。
其实 idea 挺容易明白,我说一次给你听就明白了,但是没图解释起来比较费劲。这题
最复杂的地方其实就是选择怎么把数据结构结合起来。
一开始我以为要用 dp,其实 greedy 就可以了。
总复杂度是 O(N lg M),N 为 str 的长度,M 为 pattern 的长度。
主要原因有个 lg M 是因为 STL map 里的 find() 函数复杂度为 O(lg M).
我用的是 map + queue + hashtable (有点吓人呵呵,可能我想太复杂了)。
我暂时还没想到怎么提升到 O(N),应该是利用一个更好的数据结构吧。如果有高人知
道怎么提升到 O(N),请指点一下吧~
这是我做的 test cases:
第一行是 string 和 pattern,
第二行是函数 return 的 start and end position,然后是 shortest substring。
cabeca cae
3 5 eca
cfabeca cae
4 6 eca
cabefgecdaecf cae
9 11 aec
cabwefgewcw... 阅读全帖
P********l
发帖数: 452
31
来自主题: JobHunting版 - Facebook Hacker Cup
Interesting.
The first problem is similar to one trivial interview question.
Double Squares
A double-square number is an integer X which can be expressed as the sum of
two perfect squares. For example, 10 is a double-square because 10 = 3^2 + 1
^2. Your task in this problem is, given X, determine the number of ways in
which it can be written as the sum of two squares. For example, 10 can only
be written as 3^2 + 1^2 (we don't count 1^2 + 3^2 as being different). On
the other hand, 25 can be writ... 阅读全帖
i**********e
发帖数: 1145
32
来自主题: JobHunting版 - Facebook Hacker Cup
I have tried this approach.
N can go up to 2147483647,
which requires at least 2GB to store the mappings.
In my C program it fails to allocate such large amount of memory on the heap.
一些常见面试题的答案与总结 -
http://www.ihas1337code.com
P********l
发帖数: 452
33
来自主题: JobHunting版 - Facebook Hacker Cup
how can it be?
sqrt(2147483647)=46340.95 ~ several hundreds kB.
It should be a hash set instead. It make no sense to have a hash map with
value true/false.

heap.
g*********s
发帖数: 1782
34
来自主题: JobHunting版 - 经典题atoi的溢出处理
int atoi(const char* s);
assuming INT_MAX = 2^31-1, INT_MIN = -2^31, the following must hold:
atoi("2147483648") = 2147483647
atoi("-2147483649") = -2147483648
but this seems a little tricky. any elegant solution to handle the
overflow?
c******w
发帖数: 102
35
来自主题: JobHunting版 - 写了个sqrt,请点评
if (mid * mid > i) {
high = mid;
} else {
low = mid;
}
这个地方可能出现溢出。 因为 double low = 1, high = i; 如果i的值本身比较大,
那么 mid*mide 的值很可能会比i的值大。 举个例子来说, 如果这个函数是求一个int
i的sqrt.假定 i= 2147483647, 那么你的mid值就会是 mid = low + (high - low) /
2 = 1073741823, 显然 1073741823* 1073741823的值比最大的int数要大多了。 类
似的问题也会发生到double类型上来。
比较好的办法是不是应该在初始化high的时候选择个适当大小的数字。 比如说 high =
1 << 32 如果是求double类型数字的sqrt。
c******w
发帖数: 102
36
来自主题: JobHunting版 - 写了个sqrt,请点评
if (mid * mid > i) {
high = mid;
} else {
low = mid;
}
这个地方可能出现溢出。 因为 double low = 1, high = i; 如果i的值本身比较大,
那么 mid*mide 的值很可能会比i的值大。 举个例子来说, 如果这个函数是求一个int
i的sqrt.假定 i= 2147483647, 那么你的mid值就会是 mid = low + (high - low) /
2 = 1073741823, 显然 1073741823* 1073741823的值比最大的int数要大多了。 类
似的问题也会发生到double类型上来。
比较好的办法是不是应该在初始化high的时候选择个适当大小的数字。 比如说 high =
1 << 32 如果是求double类型数字的sqrt。
n**e
发帖数: 116
37
来自主题: JobHunting版 - atoi很不好写,头都大了...
看到版上太多关于atoi的讨论,我贴一个我的实现,希望对有所帮助。如发现bugs,请
指正。
//--------------------------------------------------------------------
// Convert a string to an integer
// How to handle overflow issue:
// Compute the cutoff value between legal numbers and illegal
// numbers. That is the largest legal value, divided by the
// base. An input number that is greater than this value, if
// followed by a legal input character, is too big. One that
// is equal to this value may be valid or not; the limit
// between... 阅读全帖
m***o
发帖数: 41
38
来自主题: JobHunting版 - 请教一道面试题
A non-empty zero-indexed array A consisting of N integers is given. A pair
of integers (P, Q) is called K-complementary in array A if 0 = P, Q < N and
A[P] + A[Q] = K.
For example, consider array A such that
A[0] = 1 A[1] = 8 A[2]= -3
A[3] = 0 A[4] = 1 A[5]= 3
A[6] = -2 A[7] = 4 A[8]= 5
1,8,-3,0,1,3,-2,4,5
The following pairs are 6-complementary in array A: (0,8), (1,6), (4,8), (5,
5), (6,1), (8,0), (8,4). For instance, the pair (4,8) is 6-complementary
because A[4] + A[8] = 1 + 5 = 6.... 阅读全帖
n**e
发帖数: 116
39
How to handle overflow issue on atoi? Hopefully this will be of help.
Compute the cutoff value between legal numbers and illegal numbers. That is
the largest legal value, divided by the base. An input number that is
greater than this value, if followed by a legal input character, is too big.
One that is equal to this value may be valid or not; the limit between
valid and invalid numbers is then based on the last digit.
For instance, if the range for longs is [-2147483648..2147483647] and the... 阅读全帖
n**e
发帖数: 116
40
How to handle overflow issue on atoi? Hope this is of help.
Compute the cutoff value between legal numbers and illegal numbers. That is
the largest legal value, divided by the base. An input number that is
greater than this value, if followed by a legal input character, is too big.
One that is equal to this value may be valid or not; the limit between
valid and invalid numbers is then based on the last digit.
For instance, if the range for longs is [-2147483648..2147483647] and the
input bas... 阅读全帖
n**e
发帖数: 116
41
How to handle overflow issue on atoi? Hopefully this will be of help.
Compute the cutoff value between legal numbers and illegal numbers. That is
the largest legal value, divided by the base. An input number that is
greater than this value, if followed by a legal input character, is too big.
One that is equal to this value may be valid or not; the limit between
valid and invalid numbers is then based on the last digit.
For instance, if the range for longs is [-2147483648..2147483647] and the... 阅读全帖
n**e
发帖数: 116
42
How to handle overflow issue on atoi? Hopefully this will be of help.
Compute the cutoff value between legal numbers and illegal numbers. That is
the largest legal value, divided by the base. An input number that is
greater than this value, if followed by a legal input character, is too big.
One that is equal to this value may be valid or not; the limit between
valid and invalid numbers is then based on the last digit.
For instance, if the range for longs is [-2147483648..2147483647] and the... 阅读全帖
n**e
发帖数: 116
43
How to handle overflow issue on atoi? Hope this is of help.
Compute the cutoff value between legal numbers and illegal numbers. That is
the largest legal value, divided by the base. An input number that is
greater than this value, if followed by a legal input character, is too big.
One that is equal to this value may be valid or not; the limit between
valid and invalid numbers is then based on the last digit.
For instance, if the range for longs is [-2147483648..2147483647] and the
input bas... 阅读全帖
n**e
发帖数: 116
44
How to handle overflow issue on atoi? Hope this is of help.
Compute the cutoff value between legal numbers and illegal numbers. That is
the largest legal value, divided by the base. An input number that is
greater than this value, if followed by a legal input character, is too big.
One that is equal to this value may be valid or not; the limit between
valid and invalid numbers is then based on the last digit.
For instance, if the range for longs is [-2147483648..2147483647] and the
input bas... 阅读全帖
i**********e
发帖数: 1145
45
"2147483647","-2147483648","2147483648","-2147483649"。
这几个 test case 测试你处理溢出的边界条件,很重要。
还有就是前面有空格的 case 吧,例如 " 23" 等。
i**********e
发帖数: 1145
46
因为要测试边界条件啊,因为你知道 2147483647 没有溢出,而 2147483648 溢出了,
所以测试 positive 溢出就这两个 case 就够了。
negative 溢出也就是其余两个 case.
n****r
发帖数: 471
47
来自主题: JobHunting版 - 两个整数除法的问题太刁钻了吧
用c++实现的,在leetcode上一跑就超时。
卡在
dividend = 2147483647
divisor = 1
Code 是:
int divide(int dividend, int divisor){
long a = dividend;
long b = divisor;
bool neg = false;
if(a < 0)
neg = !neg;
if(b < 0)
neg = !neg;
a = abs(a);
b = abs(b);
int d = 0;
while(b< d++;
int c = 0;
for(int i = d; i >=0; i--){
if(b< c |= 1 << i;
a -= b < }
}
if(neg)
c = -c;
return c;
}
n****r
发帖数: 471
48
来自主题: JobHunting版 - 两个整数除法的问题太刁钻了吧
用c++实现的,在leetcode上一跑就超时。
卡在
dividend = 2147483647
divisor = 1
Code 是:
int divide(int dividend, int divisor){
long a = dividend;
long b = divisor;
bool neg = false;
if(a < 0)
neg = !neg;
if(b < 0)
neg = !neg;
a = abs(a);
b = abs(b);
int d = 0;
while(b< d++;
int c = 0;
for(int i = d; i >=0; i--){
if(b< c |= 1 << i;
a -= b < }
}
if(neg)
c = -c;
return c;
}
n**e
发帖数: 116
49
来自主题: JobHunting版 - atoi的溢出处理的想法
I posted my implementation before. Here is my handling with overflow issue.
//----------------------------------------------------------------
// Compute the cutoff value between legal numbers and illegal
// numbers. That is the largest legal value, divided by the
// base. An input number that is greater than this value, if
// followed by a legal input character, is too big. One that
// is equal to this value may be valid or not; the limit
// between valid and invalid numbers is... 阅读全帖
j******2
发帖数: 362
50
难道不是
0xFFFFFFF=268435455
INT_MAX=2147483647=0x7FFFFFFF?
还是我哪儿搞错了?
1 2 下页 末页 (共2页)