ํฐ์คํ ๋ฆฌ ๋ทฐ
๐ฉ๐ป๐ป ๋ฌธ์
โ๐ป ํ์ด
๐จ Go
// https://www.acmicpc.net/problem/3986
package main
import (
"bufio"
"fmt"
"os"
"strings"
)
func main() {
reader := bufio.NewReader(os.Stdin)
writer := bufio.NewWriter(os.Stdout)
defer writer.Flush()
var n int
fmt.Fscanln(reader, &n)
var count int
for i := 0; i < n; i++ {
var input string
input, _ = reader.ReadString('\n') // ๊ณต๋ฐฑ ํฌํจํ์ฌ ์
๋ ฅ ๋ฐ๊ธฐ ์ํด ReadString() ์ฌ์ฉ
inputs := strings.Split(strings.ReplaceAll(input, "\n", ""), "")
stack := []string{inputs[0]}
for j := 1; j < len(inputs); j++ {
if len(stack) == 0 {
stack = []string{inputs[j]}
} else if stack[len(stack)-1] == inputs[j] {
stack = stack[:len(stack)-1]
} else {
stack = append(stack, inputs[j])
}
}
if len(stack) == 0 {
count++
}
}
fmt.Fprintln(writer, count)
}
๐จ Python3
# https://www.acmicpc.net/problem/3986
import sys
if __name__ == "__main__":
n = int(sys.stdin.readline())
count = 0
for i in range(n):
inputs = list(sys.stdin.readline().rstrip())
stack = [inputs[0]]
for j in range(1, len(inputs)):
if len(stack) == 0:
stack = [inputs[j]]
elif stack[-1] == inputs[j]:
stack.pop()
else:
stack.append(inputs[j])
if len(stack) == 0:
count += 1
print(count)
728x90
'dev > algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
BOJ / 17219๋ฒ / ๋น๋ฐ๋ฒํธ ์ฐพ๊ธฐ [Go][Python3] (0) | 2021.02.05 |
---|---|
BOJ / 1302๋ฒ / ๋ฒ ์คํธ์ ๋ฌ [Go][Python3] (0) | 2021.02.04 |
BOJ / 1620๋ฒ / ๋๋์ผ ํฌ์ผ๋ชฌ ๋ง์คํฐ ์ด๋ค์ [Go][Python3] (0) | 2021.02.02 |
BOJ / 10845๋ฒ / ํ [Go][Python3] (0) | 2021.02.01 |
BOJ / 1158๋ฒ / ์์ธํธ์ค ๋ฌธ์ [Go][Python3] (0) | 2021.01.31 |
๋๊ธ
๊ธ ๋ณด๊ดํจ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
TAG
- ์๊ณ ๋ฆฌ์ฆ
- ๋งฅ๋ถ ์ ๊ทธ๋ ์ด๋
- ๋ถํ ์ ๋ณต
- ์คํ
- MongoDB
- ๋งฅ๋ถ
- ํ
- Golang
- ๋ชฝ๊ณ ๋๋น
- ๋ฐฑ์ค
- BFS
- AWS
- ๋ธ๋ฃจํธํฌ์ค
- ํ๋ก์ด๋์์ฌ
- ์๋ฐ
- java
- dfs
- ํด์๋งต
- Algorithm
- go
- ์ด๋ถํ์
- ๋งฅ๋ถํ๋ก
- ๋ฐ๋
- BOJ
- dp
- ballet
- ์๊ฐ๊ต์ฒด
- Macbook pro 2012 mid 13
- baekjoon
- python3
- Total
- Today
- Yesterday