설정 비트 수를 계산하려고하는데 숫자가 오름차순으로 정렬되어 있습니다. 세트 비트의 카운트까지.다음 코드를 쓸 때 "4 3 10 7"대신 "4 10 7"출력이 나오는 이유는 무엇입니까?
내 입력은 다음과 같습니다
1
4
3 4 7 10
예상 출력은 다음과 같습니다
4 3 10 7
내 출력은 다음과 같습니다
4 10 7
표시 할 때 왜 3을 건너 뛰는? I는 A는이 값 3을 판독 여부 확인하는 값을 출력 할 때
package practice;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Collection;
import java.util.HashMap;
import java.util.TreeMap;
public class MonkAndTasks {
public static void main(String args[]) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
int k = 0;
while (k < t) {
long n = Long.parseLong(br.readLine());
String str = br.readLine();
String ar[] = str.split(" ");
int i = 0;
HashMap<Integer,Long> hm = new HashMap<Integer,Long>();
while (i < n) {
Long a = Long.parseLong(ar[i++]);
hm.put(count(a), a);
}
TreeMap<Integer,Long> tm = new TreeMap<Integer,Long>(hm);
Collection <Long> c = tm.values();
for (Long e: c) {
System.out.print(e + " ");
}
System.out.println();
}
}
static int count(Long n) {
int c = 0;
while (n > 0) {
n = n & (n - 1);
c++;
}
return c;
}
}
, 그것 값 3을 판독 되나 해시 맵 가치 및 트리 맵을 통과 한 후에 또 원하는 출력이 표시되지 않는 것으로 나타났다.
가능한 중복 (HTTP : //stackoverflow.com/questions/25385173/what-is-a-debugger-and-how-can-it-help-me-diagnose-problems) – Raedwald