-
Notifications
You must be signed in to change notification settings - Fork 0
/
izziv4.java
51 lines (47 loc) · 1.44 KB
/
izziv4.java
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import java.lang.reflect.Array;
import java.util.*;
public class izziv4 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] tabela = new int[n];
for (int i = 0; i < n; i++) {
tabela[i] = sc.nextInt();
// System.out.println(stEnic(tabela[i]));
}
uredi(tabela);
}
public static void uredi(int[] tabela) {
int[] tabelaEnic = new int[tabela.length];
for (int i = 0; i < tabela.length; i++) {
tabelaEnic[i] = stEnic(tabela[i]);
}
int[] c = new int[32];
for (int i = 0; i < tabela.length; i++) {
c[tabelaEnic[i]]++;
}
for (int i = 1; i < 32; ++i) {
c[i] += c[i - 1];
}
int[] tabela2 = new int[tabela.length];
for (int i = tabela2.length - 1; i >= 0; i--) {
tabela2[c[tabelaEnic[i]] - 1] = tabela[i];
--c[tabelaEnic[i]];
System.out.println("(" + tabela[i] + "," + (c[tabelaEnic[i]]) + ")");
}
System.out.print(tabela2[0]);
for (int i = 1; i < tabela2.length; i++) {
System.out.print(" " + tabela2[i]);
}
System.out.println();
}
public static int stEnic(int n) {
int stevec = 0;
while (n > 0) {
if (n % 2 == 1)
stevec++;
n /= 2;
}
return stevec;
}
}