CareerCup-5.1
来源:互联网 发布:违章查询软件 编辑:程序博客网 时间:2024/06/09 17:25
You are given two 32-bit numbers, N and M, and two bit positions, i and j Write a
method to set all bits between i and j in N equal to M (e g , M becomes a substring of
N located at i and starting at j)
EXAMPLE:
Input: N = 10000000000, M = 10101, i = 2, j = 6
Output: N = 10001010100
method to set all bits between i and j in N equal to M (e g , M becomes a substring of
N located at i and starting at j)
EXAMPLE:
Input: N = 10000000000, M = 10101, i = 2, j = 6
Output: N = 10001010100
第一个方法是我的思路 第二个是参考答案的思路实现的
#include <iostream>#include <bitset>using namespace std;typedef int Data;void setBits(bitset<32>* N, bitset<32>* M, int i, int j){ *N = *N^(*N<<(32-j+i-1)>>(32-j-1))^(*M<<i);};void setBits2(bitset<32>* N, bitset<32>* M, int i, int j){ bitset<32> t((~0<<(j+1)|((1<<i)-1))); *N = t&*N|(*M<<i);};int main(){ bitset<32> N((string)"10000000000"); bitset<32> M((string)"10101"); int i=2, j=6; setBits2(&N, &M, i, j); cout<<N<<endl; system("pause"); };
- CareerCup-5.1
- CareerCup 1.3
- CareerCup 1.4
- CareerCup 5.7
- CareerCup 14.6
- CareerCup 1.1
- CareerCup 1.2
- CareerCup 1.3
- CareerCup 1.4
- CareerCup 1.5
- CareerCup 1.6
- CareerCup 1.7
- CareerCup 1.8
- CareerCup 2.1
- CareerCup 2.2
- CareerCup 2.3
- CareerCup 2.4
- CareerCup 2.5
- 如何用Android InstrumentationTestRunner 执行单个case
- 关于用了beanUtils的copyProperties后Hibernate报detached entity passed to persist
- 快速提取PUZZLE & DRAGONS音效的方法
- All about goldengate
- TestCase编写总结
- CareerCup-5.1
- centos Apache、php、mysql默认安装路径
- 导入js库无效
- 异步复位和同步释放电路的详细解释
- 成为量化分析师
- Qt图片显示效率的比较
- Sping MVC http status 400 错误分析 - 陌上花开的日志 - 网易博客
- IE9弹脚本出错的窗口,卡死
- WinForm获取TextBox里分行的数据