zoukankan      html  css  js  c++  java
  • 统计2的N次方的数的个数

    package huawei;

    import java.util.Scanner;

    public class TestHuaWei {

    public static void main(String[] args) {
    Scanner in = new Scanner(System.in);

    int nCount = 0;
    try {
    if (in.hasNextLine()) {
    String line = in.nextLine();

    if (line != null && line.trim().length() > 128) {
    System.out.println("输出错误");
    }

    String iArray [] = line.split(",");

    for (int i = 0, size = iArray.length; i < size; i++) {

    int num = Integer.valueOf(iArray[i]).intValue();
    if (num == 1) {
    nCount ++;
    } else {
    if ((num & (num - 1)) == 0) {
    nCount ++;
    }
    }

    }
    }
    }catch(Exception e) {
    System.out.println("输入错误");
    } finally {
    if (in != null) {
    in.close();
    }
    }

    System.out.println(nCount);




    }

    }

  • 相关阅读:
    p1706 全排列
    2089烤鸡(类似于选数问题)
    1036选数
    bfs
    A-E
    A-3
    百题A-2
    百题A-1
    二级概念题
    随记
  • 原文地址:https://www.cnblogs.com/tiny-kong/p/4055193.html
Copyright © 2011-2022 走看看