Advertisement
vkazar

Untitled

Sep 25th, 2023
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.61 KB | None | 0 0
  1. package sprint3.tasks.I
  2. import java.io.BufferedReader
  3. import java.io.InputStreamReader
  4. import java.util.*
  5. fun main() {
  6.     val reader = BufferedReader(InputStreamReader(System.`in`))
  7.     val size = reader.readLine().toInt()
  8.     val tokenizer = StringTokenizer(reader.readLine())
  9.     List(size) { tokenizer.nextToken().toInt() }
  10.         .run {
  11.             associate { it to this.count { l -> l == it } }
  12.         }
  13.         .entries
  14.         .sortedWith(compareBy({ -it.value }, { it.key }))
  15.         .take(reader.readLine().toInt())
  16.         .map { it.key }
  17.         .joinToString(" ")
  18.         .let(::println)
  19. }
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement