Application

Report a typo

The Resistance is organizing ships to confront the Empire. They are going to reload the weapons with an upgrade that allows you to have double the ammo. For that, R2D2 has a list of maps with the value of ammunition for each ship. Can you help R2D2?

Sample Input 1:

XWing-100 YWing-200 TWing-50 TIEFighter-150

Sample Output 1:

[{XWing=200}, {YWing=400}, {TWing=100}, {TIEFighter=300}]
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()) }
val shipsListMap: List<Map<String, Int>> = shipsList.map { mapOf(it.name to it.ammunition) }

// write your code here
val res =


println(res)
}
___

Create a free account to access the full topic