class Solution { public: int divide(int dividend, int divisor) { bool flag=((dividend >0) ^ (divisor>0)); cout<<(dividend >0); cout<<(divisor >0); cout<<flag<<endl; /*if(divisor==1) return dividend; if(divisor==-1) return -dividend; if(dividend==divisor) return 1; if(dividend==-divisor) return -1;*/ uint64_t end=(unsigned int)(abs(dividend)); uint64_t sor=(unsigned int)(abs(divisor)); cout<<end<<" "<<sor<<endl; long long res=0; int p=0; while(end>=sor){ res+=pow(2,p++); end-=sor; sor <<= 1; // } //cout<<" fdfsdf"<<res<<endl; cout<<end<<" "<<sor<<endl; if(p){ p--; sor >>=1; //cout<<end<<"---"<<sor<<endl; while(end >0 ){ //cout<<end<<" "<<sor<<endl; while(end>=sor){ res+=pow(2,p); cout<<end<<" "<<sor<<endl; cout<<" fdfsdf"<<res<<endl; end-=sor; } sor >>= 1; p--; } } if(!flag) cout<<"-----"<<res; return flag?-res:res; } };
这题让我好厌烦,,这种判断边界。。。。