A long time ago in a galaxy far, far away....

Report a typo

The Jedi-Sith War was the last of the wars fought between the Jedi Order and the Sith Order during the fall of the Old Republic. The Jedi are powerful guardians of order and justice, but the Sith are the antithesis and an ancient enemy of the Jedi – they are ruthless and totalitarian.

Given a list of characters, obtain the number of the Jedi and the Sith. Note: some of the Sith may have a mask (true/false).

Sample Input 1:

luke-jedi-25 leia-jedi-25 darkvader-sith-true darksidiuos-sith-false

Sample Output 1:

jedis: 2, siths: 2
Write a program in Kotlin
open class Character(val name: String)
class Jedi(name: String, val age: Int) : Character(name)
class Sith(name: String, val hasMask: Boolean) : Character(name)

fun characterBuilder(input: String): Character {
val (name, type, other) = input.split("-")
return when (type) {
"jedi" -> Jedi(name, other.toInt())
"sith" -> Sith(name, other.toBoolean())
else -> throw IllegalArgumentException("Unknown character type: $type")
}
}

fun main() {
val list = readln().split(" ")
val characters = list.map { characterBuilder(it) }

// write your code here


println("jedis: ${jedis.size}, siths: ${siths.size}")
}
___

Create a free account to access the full topic