-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolution.kt
36 lines (35 loc) · 907 Bytes
/
solution.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
val regex = Regex("""(IV|IX|XL|XC|CD|CM)""")
fun main(args: Array<out String>) {
var count = readLine()!!.toInt()
while(count --> 0) {
val result = readLine()!!.replace(regex) {
when (it.groupValues[0]) {
"IV" -> "a"
"IX" -> "b"
"XL" -> "c"
"XC" -> "d"
"CD" -> "e"
"CM" -> "f"
else -> "?"
}
}.sumBy {
when (it) {
'I' -> 1
'a' -> 4
'V' -> 5
'b' -> 9
'X' -> 10
'c' -> 40
'L' -> 50
'd' -> 90
'C' -> 100
'e' -> 400
'D' -> 500
'f' -> 900
'M' -> 1000
else -> 0
}
}
println(result)
}
}