位运算实现加法求助
查看原帖
位运算实现加法求助
310664
吴锦洋楼主2020/12/19 17:38
#include<cstdio>
#include<iostream>
using namespace std;
int d(int q,int s)
    {int r=s;
    while(q&r)
    {
    q=q^r;  
    r=r<<1;
    }
    q=q|r;
    return q;
    }
int j(int a,int b)
    {
        int q=1;
        while(q<=b)
        {
        if(q&b)
        a=d(a,q); 
        q=q<<1;
        }
        return a;
    }
int main()
{
int a,b;
cin>>a>>b;
cout<<j(a,b);
return 0;
}
2020/12/19 17:38
加载中...