-
Notifications
You must be signed in to change notification settings - Fork 201
Expand file tree
/
Copy pathTask04Main.java
More file actions
32 lines (25 loc) · 1.01 KB
/
Task04Main.java
File metadata and controls
32 lines (25 loc) · 1.01 KB
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
package com.example.task04;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Comparator;
import java.util.Map;
import java.util.function.ToLongFunction;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class Task04Main {
public static void main(String[] args) {
BufferedReader reader = new BufferedReader( new InputStreamReader(System.in));
reader.lines()
.map(String::toLowerCase)
.flatMap(x -> Stream.of(x.split("[^a-zа-яё0-9]")))
.filter(x -> !x.isEmpty())
.collect(Collectors.groupingBy(x -> x, Collectors.counting()))
.entrySet()
.stream()
.sorted(Comparator.comparingLong((ToLongFunction<Map.Entry<String,Long>>) Map.Entry::getValue)
.reversed()
.thenComparing(Map.Entry::getKey))
.limit(10)
.forEach(t -> System.out.print(t.getKey() + "\n"));
}
}