1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
import java.util.Scanner; /** * UVA10019 */ public class UVA10019 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int count = sc.nextInt(); for (int i = 0; i < count; i++) { int num = sc.nextInt(); String bin = Integer.toBinaryString(num); int hexNum = Integer.parseInt(Integer.toString(num), 16); String hex = Integer.toBinaryString(hexNum); int binFreq = 0, hexFreq = 0; for (int j = 0; j < bin.length(); j++) if (bin.charAt(j) == '1') binFreq++; for (int j = 0; j < hex.length(); j++) if (hex.charAt(j) == '1') hexFreq++; System.out.printf("%d %d\r\n", binFreq, hexFreq); } sc.close(); } } |