标签:space ace using cpp names 计算 int map str
/*
题目:
在不使用加减乘除的前提下,计算两个整数之和。
思路:
不能使用加减乘除则只能考虑位运算。
x=num1^num2,则为抹掉进位的结果。
y=num1&num2,为只有进位的结果。
(y<<1)&x,直到不产生进位。
*/
#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
int Add(int num1, int num2)
{
int x = num1 ^ num2;
int y = num1 & num2;
while(y != 0){
int temp = x ^ (y << 1);
y = x & (y << 1);
x = temp;
}
return x;
}
int main(){
cout<<Add(5,17);
}
标签:space ace using cpp names 计算 int map str
原文地址:https://www.cnblogs.com/buaaZhhx/p/12141662.html