The Empire strikes back

Report a typo

The Resistance is organizing ships to confront the Empire. R2D2 has a list with the ships. The droid should get the last ship in the strike group whose ammunition is greater than 200. You must help R2D2 organize defense against the empire and code the droid's AI to print only the name of the ship or "No ship found" if it does not exist.

Sample Input 1:

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

Sample Output 1:

TIEFighter
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

}
___

Create a free account to access the full topic