ΠΡΠΈΠ±ΠΊΠ° Π² ΡΠ°ΠΉΠ»Π΅ com/javarush/task/task18/task1803/Solution.java Π² ΡΡΡΠΎΠΊΠ΅ : 25
ΠΠ΅ Π½Π°ΠΉΠ΄Π΅Π½ ΠΌΠ΅ΡΠΎΠ΄ "readAllBytes()" Π² ΠΏΠ΅ΡΠ΅ΠΌΠ΅Π½Π½ΠΎΠΉ "fileInputStream"
Π²ΡΠ΄Π°Π΅Ρ ΡΠ°ΠΊΠΎΠ΅ Π²ΠΎΡ ΡΠΎΠΎΠ±ΡΠ΅Π½ΠΈΡ ΠΏΡΠΈ ΠΎΡΠΏΡΠ°Π²ΠΊΠ΅ Π½Π° ΠΏΡΠΎΠ²Π΅ΡΠΊΡ Π·Π°Π΄Π°ΡΠΈ
Π²ΠΎΡ ΠΊΠΎΠ΄
public class Solution {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
String file = sc.nextLine();
FileInputStream fileInputStream = new FileInputStream(file);
Map<Byte, Integer> savedBytes = new HashMap<>();
byte[] tmp;
tmp = fileInputStream.readAllBytes();
Arrays.sort(tmp);
int iterator = 1;
for (int i = 0; i < tmp.length; i++) {
for (int j = i + 1; j < tmp.length; j++) {
if (tmp[i] == 0) {
i++;
continue;
}
if (tmp[i] == tmp[j]) {
if (j - i == 1) {
iterator++;
savedBytes.put(tmp[i], iterator++);
tmp[j] = 0;
} else {
savedBytes.put(tmp[i], iterator++);
tmp[j] = 0;
}
}
}
iterator = 0;
}
byte biggest;
int count;
int index = 0;
ArrayList<Byte> keys = new ArrayList<>();
ArrayList<Integer> counts = new ArrayList<>();
keys.addAll(savedBytes.keySet());
counts.addAll(savedBytes.values());
int max = counts.get(0);
for (int i = 1; i < counts.size(); i++) {
if (counts.get(i) > max) {
max = counts.get(i);
index = counts.indexOf(max);
}
}
for (int i = 0; i < index; i++) {
System.out.print(keys.get(index) + " ");
}
}
}