Harry Potter is learning different spells. He has a list of spells with their power values. He wants to group them by their power.
Grouping collections
Harry and the Spell Power
Report a typo
Sample Input 1:
expetum-50 patronus-20 axio-50 lithigum-20 madriketom-70Sample Output 1:
{50=[Spell(name=expetum, power=50), Spell(name=axio, power=50)], 20=[Spell(name=patronus, power=20), Spell(name=lithigum, power=20)], 70=[Spell(name=madriketom, power=70)]}Write a program in Kotlin
data class Spell(val name: String, val power: Int)
fun main() {
val input = readln().split(" ")
val spells = input.map { Spell(it.split("-")[0], it.split("-")[1].toInt()) }
// write your code here
val res =
println(res)
}
___
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.