Skip to content

Commit 727404f

Browse files
authored
I will come to you
whenever I journey to Spain, I will come to you. For I hope to see you on my journey, and to be helped on my way there by you, if first I may enjoy your company for a while. (Romans 15:24)
1 parent 6b0c1f0 commit 727404f

1 file changed

Lines changed: 82 additions & 0 deletions

File tree

‎task18/task1804/Solution.java‎

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
2+
//whenever I journey to Spain, I will come to you. For I hope to see you on my journey, and to be helped on my way there by you, if first I may enjoy your company for a while. (Romans 15:24)
3+
4+
5+
package com.javarush.task.task18.task1804;
6+
7+
import java.io.FileInputStream;
8+
import java.io.BufferedReader;
9+
import java.io.IOException;
10+
import java.io.InputStreamReader;
11+
import java.util.HashMap;
12+
import java.util.Map;
13+
14+
15+
/*
16+
Самые редкие байты
17+
*/
18+
19+
public class Solution {
20+
public static void main(String[] args) throws Exception {
21+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
22+
FileInputStream fileInputStream = new FileInputStream(br.readLine());
23+
try {
24+
25+
Map<Integer, Integer> map = new HashMap<>();
26+
int min = Integer.MAX_VALUE;
27+
while (fileInputStream.available() > 0) {
28+
int newValue = map.merge(fileInputStream.read(), 1, (o, n) -> o + n);
29+
if (newValue < min) {
30+
min = newValue;
31+
}
32+
}
33+
34+
for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
35+
if (entry.getValue() == min) {
36+
System.out.print(entry.getKey() + " ");
37+
}
38+
}
39+
40+
} catch (IOException e) {
41+
e.printStackTrace();
42+
}
43+
try{
44+
fileInputStream.close();
45+
br.close();
46+
}catch(IOException e) {e.printStackTrace();}
47+
48+
}
49+
}
50+
51+
52+
53+
54+
55+
/*
56+
Самые редкие байты
57+
Ввести с консоли имя файла.
58+
Найти байт или байты с минимальным количеством повторов.
59+
Вывести их на экран через пробел.
60+
Закрыть поток ввода-вывода.
61+
62+
63+
Требования:
64+
1. Программа должна считывать имя файла с консоли.
65+
2. Для чтения из файла используй поток FileInputStream.
66+
3. В консоль через пробел должны выводиться все байты из файла с минимальным количеством повторов.
67+
4. Данные в консоль должны выводится в одну строку.
68+
5. Поток чтения из файла должен быть закрыт.
69+
70+
package com.javarush.task.task18.task1804;
71+
72+
import java.io.FileInputStream;
73+
74+
/*
75+
Самые редкие байты
76+
*/
77+
78+
public class Solution {
79+
public static void main(String[] args) throws Exception {
80+
}
81+
}
82+
*/

0 commit comments

Comments
 (0)