CC35:加法运算替代
class AddSubstitution {
public:
int calc(int a, int b, int type) {
// write code here
int result=0;
switch(type){
case 1:
for(int i=0;i<b;i++)
result+=a;
break;
case 0:
if (b == 0) return -1;
if (a < b) return 0;
while (a >= b)
{
int temp = 1;
while (b*temp < a)
{
temp = temp << 1;
}
if (b*temp == a)
{
result += temp;
a = 0;
}
else
{
result += (temp >> 1);
a = a - b*(temp >> 1);
}
}
break;
case -1:
b=-b;
result=a+b;
break;
default:
break;
}
return result;
}
};
作者:YunLambert
-------------------------------------------
个性签名:一名会音乐、爱健身的不合格程序员
可以Follow博主的Github哦(っ•̀ω•́)っ✎⁾⁾