AcWing 801. 二进制中1的个数 ( JavaScript )
原题链接
简单
作者:
gaobowen
,
2019-11-14 18:17:29
,
所有人可见
,
阅读 690
let lowbitCount = arr => {
return arr.map(val => {
let num = new Int32Array(1);
num[0] |= val & 0xffffffff;
let count = 0;
while (num[0] > 0) {
count++;
num[0] -= num[0] & - num[0];
}
return count;
})
}
var buf = '';
process.stdin.on('readable', function () {
var chunk = process.stdin.read();
if (chunk) buf += chunk.toString();
});
let getInputArgs = line =>
line.split(' ').filter(s => s !== '').map(x => parseInt(x));
process.stdin.on('end', function () {
buf.split('\n').forEach(function (line, lineIdx) {
if (lineIdx === 1)
console.log(lowbitCount(getInputArgs(line)).join(' '))
});
});