g*****r 发帖数: 1037 | 1 问了PHD 做的一些PROJECT,最后有道简单的PROGRAMMING题目,用C实现ATOI一时没想
起来最优解法,悲剧。。。。 |
r********r 发帖数: 2912 | 2 atoi还有什么优不优的啊?不是一位一位算吗...
【在 g*****r 的大作中提到】 : 问了PHD 做的一些PROJECT,最后有道简单的PROGRAMMING题目,用C实现ATOI一时没想 : 起来最优解法,悲剧。。。。
|
g*****r 发帖数: 1037 | 3 我没有一步写出这个简单问题的BUG FREE的简洁的CODE。。。。。。
【在 r********r 的大作中提到】 : atoi还有什么优不优的啊?不是一位一位算吗...
|
m**********r 发帖数: 122 | 4 How about this one?
int my_atoi(const char *str)
{
int i=0;
while ( *str )
{
i = (i<<3) + (i<<1) + ((*str) - '0');
++str;
}
return i;
}
【在 g*****r 的大作中提到】 : 我没有一步写出这个简单问题的BUG FREE的简洁的CODE。。。。。。
|
c********0 发帖数: 112 | 5 忘了正负号吧。。。
【在 m**********r 的大作中提到】 : How about this one? : int my_atoi(const char *str) : { : int i=0; : while ( *str ) : { : i = (i<<3) + (i<<1) + ((*str) - '0'); : ++str; : } : return i;
|
c******w 发帖数: 102 | 6 而且还可能溢出。
【在 c********0 的大作中提到】 : 忘了正负号吧。。。
|
g*****r 发帖数: 1037 | 7 看来这个简单问题也不简单了啊,哎,LINKEDIN没希望了。。。。那个HIRING MANAGER
估计都对我相当无语了。。。。。,郁闷
【在 c******w 的大作中提到】 : 而且还可能溢出。
|
g*********s 发帖数: 1782 | 8 the point of atoi() is not using bit operation to simulate *.
【在 m**********r 的大作中提到】 : How about this one? : int my_atoi(const char *str) : { : int i=0; : while ( *str ) : { : i = (i<<3) + (i<<1) + ((*str) - '0'); : ++str; : } : return i;
|
l*****g 发帖数: 685 | 9 简单,但是有不少细节要考虑
overflow问题,正负号问题,非法字符(非数字的字符,+-号除外)出现在前面怎么处
理,出现在后面怎么处理
MANAGER
【在 g*****r 的大作中提到】 : 看来这个简单问题也不简单了啊,哎,LINKEDIN没希望了。。。。那个HIRING MANAGER : 估计都对我相当无语了。。。。。,郁闷
|
g*********s 发帖数: 1782 | 10 basically it's sign and overflow. the overflow condition varies with the
sign.
illegal char is actually simple. the code just stops and returns.
【在 l*****g 的大作中提到】 : 简单,但是有不少细节要考虑 : overflow问题,正负号问题,非法字符(非数字的字符,+-号除外)出现在前面怎么处 : 理,出现在后面怎么处理 : : MANAGER
|
s*****y 发帖数: 897 | 11 Why we do not look at the opensoruce software to see how they implenment?
Many of their implenmentation of atoi also have bug.
【在 l*****g 的大作中提到】 : 简单,但是有不少细节要考虑 : overflow问题,正负号问题,非法字符(非数字的字符,+-号除外)出现在前面怎么处 : 理,出现在后面怎么处理 : : MANAGER
|