0
点赞
收藏
分享

微信扫一扫

AcWing 801. 二进制中1的个数(Java)

Python百事通 2022-04-24 阅读 60

位运算呜呜呜呜 

import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        while(n -- > 0){
            int tmp = scan.nextInt();
            int ans = 0;
            while(tmp != 0){
                tmp -= tmp & (-tmp);
                ans++;
            }
            System.out.print(ans + " ");
        }
    }
}
举报

相关推荐

0 条评论