Created
April 5, 2019 07:43
-
-
Save malkoG/f06180d181b6ae61ad819cb6cddc691d to your computer and use it in GitHub Desktop.
noj.am/9935
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.* | |
fun main(args: Array<String>) = with(Scanner(System.`in`)) { | |
var state_stack = Stack<Int>() | |
val text = nextLine() | |
val pattern = nextLine() | |
var cursor = 0 | |
var result = StringBuilder() | |
for (i in 0..text.length-1) { | |
val ch = text[i] | |
result.append(ch) | |
val txt_size = result.length | |
if (ch == pattern[cursor]) { | |
cursor += 1 | |
} else { | |
if (ch == pattern[0]) { | |
state_stack.push(cursor) | |
cursor = 1 | |
} else { | |
state_stack = Stack<Int>() | |
cursor = 0 | |
} | |
} | |
if (cursor == pattern.length) { | |
result.delete(txt_size - cursor, txt_size) | |
cursor = if (state_stack.size > 0) state_stack.pop() else 0 | |
} | |
} | |
println(if (result.length == 0) "FRULA" else result.toString()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment