arrow_forward همه ارسال‌ها

جزئیات ارسال کد#1018

verified
وضعیت داوری نهایی: پذیرفته شد
terminal
زبان برنامه‌نویسی: Kotlin
schedule
ارسال‌کننده و زمان:
Parsa Alizadeh (۱ روز پیش)
descriptionsolution.kt ۲۴ خط • ۶۰۱ بایت
1fun main() {
2 val (n, p) = readln().split(" ").map { it.toLong() }
3 val (x, y) = readln().split(" ").map { it.toLong() }
4 val dir = readln().trim()
5
6 val (dx, dy) = when (dir) {
7 "N" -> -1L to 0L
8 "S" -> 1L to 0L
9 "W" -> 0L to -1L
10 "E" -> 0L to 1L
11 "NE" -> -1L to 1L
12 "NW" -> -1L to -1L
13 "SE" -> 1L to 1L
14 "SW" -> 1L to -1L
15 else -> 0L to 0L
16 }
17
18 fun wrap(v: Long): Long {
19 val r = v % n
20 return if (r < 0) r + n else r
21 }
22
23 println("${wrap(x + dx * p)} ${wrap(y + dy * p)}")
24}
کد ارسال‌شده برای داوری خودکار هاتکدز UTF-8