2016年7月4日 星期一

Q10931: Parity


https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1872

import java.util.*;

public class Main {

 public static void main(String[] args) {
  Scanner scn = new Scanner(System.in);
  while (scn.hasNext()) {
   int n = scn.nextInt();
   if (n == 0)
    break;
   System.out.printf("The parity of %s is %d (mod 2).\n",Integer.toBinaryString(n), Integer.bitCount(n));
  }
 }
}


困難度 
這題利用Java內建函示庫 Integer.toBinaryString()以及Integer.bitCount()

沒有留言:

張貼留言