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 will be the first. Please help R2D2 print the ships in the correct order for the combat where the last ship will be the first.
ArrayDeque
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-100Write a program in Kotlin
data class Ship(val name: String, val ammunition: Int) {
override fun toString(): String {
return "$name-$ammunition"
}
}
fun fixTheQueue(input: String): ArrayDeque<Ship> {
// Convert input to list of ships
val shipsList = input.split(" ").map {
val parts = it.split("-")
Ship(parts[0], parts[1].toInt())
}
// Use ArrayDeque to reorganize a list
// Put your code here
return shipsQueue
}
___
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.