From c88de846acc73554f382bc9be4aaf0f777198be3 Mon Sep 17 00:00:00 2001 From: Yuri Orlov Date: Sat, 7 Dec 2024 17:33:49 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D1=88=D0=B0=D0=B5=D0=BC=20=D0=B2?= =?UTF-8?q?=20=D0=BB=D0=BE=D0=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/CustomAdt.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/CustomAdt.kt b/src/main/kotlin/CustomAdt.kt index c30e0c4..e07e2ce 100644 --- a/src/main/kotlin/CustomAdt.kt +++ b/src/main/kotlin/CustomAdt.kt @@ -9,7 +9,13 @@ sealed interface ParseResult { object CustomAdt { fun parseInt(str: String): ParseResult { - TODO() - } + if (str.startsWith("--")) return ParseResult.Failure(1, '-') + try { + return ParseResult.Success(str.toInt()) + } catch (_: NumberFormatException) { + val pos = str.indexOfFirst { ch -> !ch.isDigit() } + return ParseResult.Failure(pos, str[pos]) + } + } } \ No newline at end of file