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 | import java.io.{BufferedReader, InputStreamReader} object Main { def main(args: Array[String]) { val stdin = new BufferedReader(new InputStreamReader(System.in)); val name1 = stdin.readLine(); val name2 = stdin.readLine(); System.out.println(flames(name1, name2)) } def flames(name1: String, name2: String): Char = { flames(remaining(name1, name2), 0, "FLAMES")(0) } def remaining(name1: String, name2: String): Int = { ((name1 diff name2) ++ (name2 diff name1)).length } def flames(length: Int, start: Int, phrase: String): String = { println(phrase) if (phrase.length == 1) phrase else { val toRemove = (start - 1 + length) % phrase.length val newPhrase = phrase.zipWithIndex.filter(_._2 != toRemove).map (_._1).toList.mkString flames(length, toRemove % newPhrase.length, newPhrase) } } } |
-
upload with new input
-
result: Success time: 0.21s memory: 211712 kB returned value: 0
aarthi trajendhar
FLAMES FLAME LAME LME ME M M
-
result: Success time: 0.21s memory: 211712 kB returned value: 0
aarthi vijayakanth
FLAMES LAMES LMES LME ME E E
-
result: Success time: 0.21s memory: 211712 kB returned value: 0
aarthi ranbir
FLAMES FLAME LAME LME ME M M
-
result: Success time: 0.22s memory: 211712 kB returned value: 0
prabhu trisha
FLAMES FLAME LAME LME ME M M
-
result: Success time: 0.21s memory: 211712 kB returned value: 0
prabhu shwetaprasad
FLAMES FLAES FLES FLE LE L L
-
result: Success time: 0.22s memory: 211712 kB returned value: 0
prabhu amalapaul
FLAMES FLMES LMES MES ME E E
-
result: Success time: 0.21s memory: 211712 kB returned value: 0
prabhu anushka
FLAMES LAMES LMES LME ME E E
-
result: Success time: 0.21s memory: 211712 kB returned value: 0
ABCD BEFG
FLAMES FLAME LAME LME ME M M
-
result: Success time: 0.21s memory: 211712 kB returned value: 0
AB BCDEFG
M
-
result: Success time: 0.21s memory: 211712 kB returned value: 0
ABCD CDEF
E



