由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 这道题,怎么做呀?
相关主题
讨论一道面试题计算乘法和除法,不用乘法和除法符号,怎么scale
两个整数除法的问题太刁钻了吧FB电面面筋顺求refer
M 家电面问一道面试题目
某银行的笔试题Divide Two Integers
这道题怎么做的?leecode上的divide two integers问题
一道twitter的题leetcode: Divide Two Integers 怎么做?
问一道 ama的除法题Divide Two Integers Answer 超时
关于除法的问题divide two integers
相关话题的讨论汇总
话题: tb话题: ta话题: int话题: scanf话题: 道题
进入JobHunting版参与讨论
1 (共1页)
c*********t
发帖数: 2921
1
Write a function to perform integer division without using either the / or *
operators. Find a fast way to do it.
s*********t
发帖数: 1663
2
就是让你把小学二年级用的除法拿程序写出来

*

【在 c*********t 的大作中提到】
: Write a function to perform integer division without using either the / or *
: operators. Find a fast way to do it.

c*********t
发帖数: 2921
3
能不能具体的说说?
比如 98 除以 5, 程序如何写?
谢谢!

【在 s*********t 的大作中提到】
: 就是让你把小学二年级用的除法拿程序写出来
:
: *

c******t
发帖数: 1500
4
用减法
int divide(int target, int divisor)
{
int result = 0;
while (target - divisor > 0)
{
target -= divisor;
++result;
}
return result;
}

【在 c*********t 的大作中提到】
: 能不能具体的说说?
: 比如 98 除以 5, 程序如何写?
: 谢谢!

c****p
发帖数: 6474
5
google booth

*

【在 c*********t 的大作中提到】
: Write a function to perform integer division without using either the / or *
: operators. Find a fast way to do it.

c****p
发帖数: 6474
6
假设A/B:
#include
int main()
{
int A, B, tB, tA, Q, R;
scanf("%d", &A);
scanf("%d", &B);
tB = B;
if (A {
Q = 0;
R = A;
}
else
{
while(A>tB)
{
tB<<=1;
}
tB >>= 1;
tA = A;
Q = 0;
while(tB >= B)
{
Q <<= 1;
if(tA >= tB)
{
tA -= tB;
Q += 1;
}
tB >>= 1;
}
R = tA;
}
printf("%d / %d = %d ... %d\n", A, B, Q, R);
return 0;
}

*

【在 c*********t 的大作中提到】
: Write a function to perform integer division without using either the / or *
: operators. Find a fast way to do it.

c****p
发帖数: 6474
7
假设A和B都正。
这个不是booth算法,但是比一个个减要快。
booth带预测,运算量更小一些。
可以扩展为支持+和-的运算

【在 c****p 的大作中提到】
: 假设A/B:
: #include
: int main()
: {
: int A, B, tB, tA, Q, R;
: scanf("%d", &A);
: scanf("%d", &B);
: tB = B;
: if (A: {

1 (共1页)
进入JobHunting版参与讨论
相关主题
divide two integers这道题怎么做的?
Divide Two Integers OJ和CCP150的做法一道twitter的题
问一道电面题问一道 ama的除法题
google 首轮面世汇报关于除法的问题
讨论一道面试题计算乘法和除法,不用乘法和除法符号,怎么scale
两个整数除法的问题太刁钻了吧FB电面面筋顺求refer
M 家电面问一道面试题目
某银行的笔试题Divide Two Integers
相关话题的讨论汇总
话题: tb话题: ta话题: int话题: scanf话题: 道题