UVA 10019 Java

import java.util.*;
import static java.lang.System.*;
public class main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int lines = sc.nextInt();
    for(int i =0; i < lines; i++)
    {
    	String input = Integer.toString(sc.nextInt());
    	String bin_str = Integer.toBinaryString(Integer.parseInt(input));
    	int count1 = 0;
    	for(int j = 0; j < bin_str.length(); j++)
    		if(bin_str.charAt(j) == '1')
    			count1 ++;
    	String hex_to_dec_str = Integer.toBinaryString(Integer.parseInt(input, 16));
    	int count2 = 0;
    	for(int j = 0; j < hex_to_dec_str.length(); j++)
    		if(hex_to_dec_str.charAt(j) == '1')
    			count2 ++;
    	System.out.println(String.format("%d %d", count1, count2));
    }
  }
};

留言

這個網誌中的熱門文章

UVA 11321 Java