The Resistance is organizing ships to confront the Empire. R2D2 has a list with the ships. The Resistance will attack using the following strategy: the last ship on the list will be the first to go. Please help R2D2 print the list of the ships in the correct order for the combat.
Stack
The Empire strikes back
Report a typo
Sample Input 1:
XWing-100 YWing-200 TWing-50 TIEFighter-300Sample Output 1:
[TIEFighter-300, TWing-50, YWing-200, XWing-100]Write a program in Kotlin
import java.util.*
class Ship(val name: String, val ammunition: Int) {
override fun toString(): String {
return "$name-$ammunition"
}
}
fun main() {
val ships = readln().split(" ")
val shipsList = ships.map { Ship(it.split("-")[0], it.split("-")[1].toInt()) }
// write your code here
}
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.