From 4dc6c0045fd802326b8795de139d1ac789cf84ad Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 14 Sep 2026 11:45:58 +0300 Subject: [PATCH] output functions have been fixed --- stars/Main.kt | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/stars/Main.kt b/stars/Main.kt index 8e20d6c..1400347 100644 --- a/stars/Main.kt +++ b/stars/Main.kt @@ -1,3 +1,5 @@ +import kotlin.collections.firstOrNull + // Класс для храниения звезд data class Star (val identifier: Int, val constellation: Int, @@ -54,13 +56,15 @@ fun printConstellationInfo(constellation: Constellation){ } fun getConstellation(): String{ println("Введите созвездие:") - val constellationsList = constellations.map { it.name } var constellationName: String = readln().lowercase().replaceFirstChar { it.uppercase() } while (true) { - if (constellationName in constellationsList){ + + if (constellations.firstOrNull{it.name == constellationName} != null){ break } - println("Список созвездий: ${constellationsList.joinToString(", ")}") + print("Список созвездий: ") + constellations.forEach { print(it.name) } + println() constellationName = readln().lowercase().replaceFirstChar { it.uppercase() } } @@ -224,13 +228,14 @@ fun main(){ println("Введите звезду:") // Находим id созвездия val constellationId: Int? = (constellations.firstOrNull {it.name == constellationName})?.identifier - val starsList = stars.filter{it.constellation == constellationId }.map{it.name} var starName: String = readln().lowercase().replaceFirstChar { it.uppercase() } while (true) { - if (starName in starsList){ + if (stars.firstOrNull{it.name == starName && it.constellation == constellationId} != null){ break } - println("Список звезд: ${starsList.joinToString(", ")}") + println("Список звезд: ") + stars.forEach { print(it.name + " ") } + println() starName = readln().lowercase().replaceFirstChar { it.uppercase() }