Application

Report a typo

The Resistance is organizing ships to confront the Empire. R2D2, a droid loyal to Luke Skywalker, using its AI must select the ships for combat according to the ammo. We must group them by the type of ship and add the total ammunition of each type.

Sample Input 1:

XWing-10 YWing-20 TIEFighter-30 YWing-50 TIEFighter-20 XWing-10

Sample Output 1:

{XWing=20, YWing=70, TIEFighter=50}
Write a program in Kotlin
data class Ship(val name: String, val ammunition: Int)

fun main() {
val ships = readln().split(" ")
val shipsList = ships.map { Ship(it.split("-")[0], it.split("-")[1].toInt()) }

// write your code here
val res =


println(res)
}
___

Create a free account to access the full topic