-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
16-janghw0126 #183
base: main
Are you sure you want to change the base?
16-janghw0126 #183
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ λ μ²μμ λ¨μνκ² νν λ¬Έμμ΄μ΄ μμ λκΉμ§ replaceλ‘ μ§μμ£Όλ©΄ λμ§ μμκΉ? νκ³ μλμ²λΌ μ½λλ₯Ό μμ±νλλ λ°λ‘ λ©λͺ¨λ¦¬ μ΄κ³Όκ° λ¬μ΅λλ€,,,
while(str.indexOf(bomb) != -1) {
str = str.replace(bomb, "")
}
κ·Έλμ μ λ μ€νμ μ¨λ³ΌκΉ νλ€κ° gptνν
μ€ν μ μ°κ³ ν΄κ²°ν μ μλ λ°©λ²μ μλ €λ¬λΌκ³ νλλ μλμ κ°μ μ½λλ₯Ό μλ €μ€¬μ΄μ!
νμ§λ§ μ½λ λ΄μ©μ λ―μ΄λ³΄λ©΄ μ¬μ€μ Stack μλ£νμ λ°λ‘ μ°μ§ μμλ€λ κ² λΏμ΄μ§ λμ μ리λ Stackκ³Ό λμΌνκ³ , νμ λ νμ΄λλ κ°μ κ±°λλΌκ΅¬μ π€
fun main() {
val br = BufferedReader(InputStreamReader(System.`in`))
var str = br.readLine()
val bomb = br.readLine()
val bombLen = bomb.length
val result = StringBuilder()
for (char in str) {
result.append(char)
if (result.endsWith(bomb)) {
result.delete(result.length - bombLen, result.length)
}
}
if (result.isEmpty()) {
println("FRULA")
} else {
println(result.toString())
}
}
fun StringBuilder.endsWith(suffix: String): Boolean {
if (this.length < suffix.length) return false
return this.substring(this.length - suffix.length) == suffix
}
μ΄λ² μ°¨μλ μκ³ νμ ¨μ΄μ!
for str in string: | ||
stack.append(str) | ||
# νλ° λ¬Έμμ΄κ³Ό stack λ·λΆλΆμ΄ κ°μ κ²½μ° | ||
if ''.join(stack[-bomb_len:])==bomb_string: | ||
# ν΄λΉ λ¬Έμμ΄ pop | ||
for _ in range(bomb_len): | ||
stack.pop() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
''.join()μ μ¬μ©νμ¬ λ¬Έμμ΄μ λΉκ΅νλ λΆλΆμ μ΅μ ννμ¬ μκ°μ μ‘°κΈ λ μ€μ¬λ³΄μμ΅λλ€ !
- νλ° λ¬Έμμ΄μ λ§μ§λ§ λ¬Έμλ₯Ό λ¨Όμ νμΈνμ¬ λΆνμν λ¬Έμμ΄ λΉκ΅λ₯Ό μ€μμ΅λλ€.
- ''.join() νΈμΆμ μ΅μννμ΅λλ€.
for char in string:
stack.append(char)
# νμ¬ λ¬Έμκ° νλ° λ¬Έμμ΄μ λ§μ§λ§ λ¬Έμμ κ°κ³
# μ€νμ κΈΈμ΄κ° νλ° λ¬Έμμ΄ μ΄μμΌ λλ§ κ²μ¬
if char == last_char and len(stack) >= bomb_len:
# νλ° λ¬Έμμ΄κ³Ό μΌμΉνλμ§ μ§μ λΉκ΅
is_bomb = True
for i in range(bomb_len):
if stack[-(bomb_len-i)] != bomb[i]:
is_bomb = False
break
if is_bomb:
del stack[-bomb_len:] # pop() λμ del μ¬μ©νμ¬ νλ²μ μ κ±°
print(''.join(stack) if stack else "FRULA", end='')
μλ μ½λλ³΄λ€ μ‘°κΈ λ μκ°μ΄ λΉ¨λΌμ§ κ²μ νμΈν μ μμμ΅λλ€ !
π λ¬Έμ λ§ν¬
λ°±μ€ | λ¬Έμμ΄ νλ°
βοΈ μμλ μκ°
50λΆ
β¨ μλ μ½λ
πλ¬Έμ μ½λ λ°λ‘κ°κΈ°
μ΄ λ¬Έμ λ μ€νμ μ¬μ©ν΄μΌ νλ μμ΄λμ΄λ§ νμ νλ©΄ μ½κ² ν΄κ²°ν μ μμ΅λλ€.
κ·ΈμΉλ§ λ¬Έμμ΄μ μ λ ₯λ°μμΌ λκΈ° λλ¬Έμ μ΄λ₯Ό μ²λ¦¬νλ λΆλΆμμ μ‘°κΈ κΉλ€λ‘μ μ΅λλ€.
λ¬Έμ μμλ λ¬Έμμ΄μ νλ° λ¬Έμμ΄μ μ¬μ΄λμκ³ , νλ° λ¬Έμμ΄μ ν¬ν¨νκ³ μλ κ²½μ°μ ν΄λΉ λ¬Έμμ΄μ μμ€ ν λ¨μ λ¬Έμμ΄μ μμλλ‘ μ΄μ΄ λΆμ¬ μλ‘μ΄ λ¬Έμμ΄μ λ§λ λ€κ³ νμμ΅λλ€.
κ·Έλμ μ λ μ€νμ μ°¨λ‘λλ‘ λ¬Έμ νλνλλ₯Ό λ£μΌλ©΄μ νλ° λ¬Έμμ΄κ³Ό μ€νμ μλ λ¬Έμμ΄μ λΉκ΅νμ¬ νλ° λ¬Έμμ΄μ΄ μλμ§ νμΈνκ³ μλ κ²½μ°
pop()
μ νλ©΄ λκ² λ€κ³ μκ°νμμ΅λλ€.π λ¬Έμ λ‘μ§
π©βπ»μ΅μ’ μ½λ
π μλ‘κ² μκ²λ λ΄μ©
μν κΈ°κ°μ΄ λλ λλ¬μλλ€,,,π
μν 곡λΆλ₯Ό νλλΌ μκ³ λ¦¬μ¦ κ°μ μ΄μ§ μμ΄λ²λ €μ μλ°μ κ²Έ ꡬν λ¬Έμ λ₯Ό νμ΄λ³΄μλλ° μμ§ λΆμ‘±ν¨μ λλλλ€..γ
PRμ΄ λ°λ¦°λ§νΌ μ΄μ¬ν λ¬λ €λ³΄κ² μ΅λλ€!