Divide Two Integers
2015-08-03 15:16
399 查看
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; } };
这题让我好厌烦,,这种判断边界。。。。
相关文章推荐
- (转)c++迭代器
- Oracle中的CHR()函数与ASCII()函数
- Oracle中的CHR()函数与ASCII()函数
- Linux cp复制
- Ruby中的集合编写指南
- 解决SQLServer远程连接失败的问题
- iOS开发中tableview中cell分隔线与左右的距离
- 【Android进阶学习】监听EditText的变化
- 南阳OJ~~水仙花数
- POJ 2513 Colored Sticks(字典树+并查集+欧拉回路)
- HTTP Live Streaming直播(iOS直播)技术分析与实现
- HashMap源码分析
- 解决双缓存仍然闪烁的问题
- Linux下端口被占用解决
- 轻松java学习之路4
- leetcode-Best Time to Buy and Sell Stock
- linux添加、删除用户
- 集群基础知识详解
- Ubuntu 中安装 NetBeans IDE 8.0
- NVIDIA cuda7在centos6.5中的安装