ํฐ์คํ ๋ฆฌ ๋ทฐ
๐ฉ๐ป๐ป ๋ฌธ์
โ๐ป ํ์ด
๐จ 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
- ํด์๋งต
- dp
- ๋งฅ๋ถ ์ ๊ทธ๋ ์ด๋
- ์ด๋ถํ์
- ํ๋ก์ด๋์์ฌ
- ballet
- go
- python3
- ์คํ
- MongoDB
- ์๊ฐ๊ต์ฒด
- ๋ธ๋ฃจํธํฌ์ค
- ์๊ณ ๋ฆฌ์ฆ
- Algorithm
- ๋ชฝ๊ณ ๋๋น
- BFS
- AWS
- ๋ฐฑ์ค
- java
- ๋ถํ ์ ๋ณต
- dfs
- BOJ
- ๋งฅ๋ถ
- baekjoon
- ๋ฐ๋
- ๋งฅ๋ถํ๋ก
- Golang
- ํ
- ์๋ฐ
- Macbook pro 2012 mid 13
- Total
- Today
- Yesterday