摘要: 转载:http://hi.baidu.com/zengzhaonong/item/b8e4e78ea7e8a3d45f0ec17b求下面函数的返回值(微软) -- 统计1的个数-------------------------------------int func(int x){ int countx = 0; while(x) { countx++; x = x&(x-1); } return countx;} 假定x = 9999 10011100001111 答案: 8思路: 将x转化为2进制,看含有的1的个数。 注: 每执行一次x = x&(x... 阅读全文
posted @ 2013-03-07 14:18 logx 阅读(197) 评论(0) 推荐(0) 编辑